Alternative ways to 'check' a web form checkbox/radio button

tx12345

Board Regular
Joined
Aug 28, 2006
Messages
165
hi
let's say you want to navigate a web form with lots of checkboxes and radio buttons, where the usual code:

Set F6 = .document.all.Item("A")
F6.Checked = True

just won't cut it, because it is an onclick sort of thing, where even if the above code infills the checkbox, it still doesn't trigger a 'check' (i know, i know, it is hard to believe, but it happens)

since i was not able to get an answer to a better altenative (where you still go directly by name to the item in the form and 'check' thebox by some other means), the only other solution i found that worked was send keys.

a good link for send keys can be found pretty easily. with send key it acts the same as if you were there navigating the web page with a mouse, with the notable caveat that send keys can be inconsistent. one day (TAB 3} (tabbing three times) will put you in check box 'A' where you want to be, and the next day you'll be in check box 'B' whee you don't want. the way to deal with this annoying bugette is to (at least this is what i found) have your macro clear ot the cookie on the users computer that refers to the site in question. in my case i found that if the cookie was not cleared the tab jumped two on me, but when the cookie was cleared it always starts in the right place. since i'll have no idea whether on not a user will hve cookies cleared or not cleared, the best thing to do is clear the cookie first.

for my tutorial on how to do this:

Click Here

So setting up a send keys navigation routine was not the hard part - it was dealing with the cookie that was. now you can use send keys with a clear cookie and have a greatly improved chance the box you want checked will be checked.

but if there is another way besides this:

Set F6 = .document.all.Item("A")
F6.Checked = True

to 'check' a box on a web form that refuses to do so with the above code, i am all ears.


tx
 

Some videos you may like

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
L

Legacy 98055

Guest
You would use:

Set F6 = .document.all.Item("A")
F6.Click

Am I missing something here? With IE and the DOM, I have only run into one scenario using code that you could not duplicate a user action.

Tx. Any way you could provide an example URL where this is a problem?
 

tx12345

Board Regular
Joined
Aug 28, 2006
Messages
165
Hi Tom

thanks for the reply. took some time off. i'll give the code a try. will post a similar question in a new thread.

thaks again

tx




You would use:

Set F6 = .document.all.Item("A")
F6.Click

Am I missing something here? With IE and the DOM, I have only run into one scenario using code that you could not duplicate a user action.

Tx. Any way you could provide an example URL where this is a problem?
 

mahukumar

New Member
Joined
Jul 25, 2006
Messages
11
Radio Button

Hi In the following url i need to download the data into an excel file. I have stuck up in middle where i need to click Radio button called "All Items", Need your help.

Private Sub CommandButton1_Click()
Dim ie As Object
Dim qrySht As Worksheet
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
.Navigate "http://www.pcrichard.com/cgi-bin/lansaweb?procfun+homeproc01+pghome+pcr+eng"

Do Until .ReadyState = 4: DoEvents: Loop
Do While .busy: DoEvents: Loop



Set mytextfield = .document.all.Item("APRDSRC")
mytextfield.Value = "GE"
' ie.document.forms(1).submit
' ie.document.all.Item("GO").Click

SendKeys "{TAB}", True
SendKeys "{TAB}", True
SendKeys "{TAB}", True
SendKeys "{TAB}", True
SendKeys "{TAB}", True
SendKeys "{TAB}", True
SendKeys "{TAB}", True
SendKeys "{TAB}", True
SendKeys "{TAB}", True
SendKeys "{TAB}", True
SendKeys "{Tab}", True
SendKeys "{Enter}", True

Do Until .ReadyState = 4: DoEvents: Loop
Do While .busy: DoEvents: Loop
'Set F6 = .document.all.Item("LWK_INVLVL")
'F6.Click

' Doc.getElementById("LWK_INVLVL").Click
End With

Set doc = ie.document
GetAllTables2 doc




End Sub

Sub GetAllTables2(d)
'To add worksheets in the workbook
'Worksheets.Add After:=Sheet3, Count:=3
'' SendKeys "{TAB}", True
'' SendKeys "{ENTER}", True


For Each e In d.all
If e.nodename = "TABLE" Then
Set t = e
tabno = tabno + 1
' To take only the Table no 49, 50 and 51 use if loop
'if you remove the if loop it will copy all the tables into excel sheet
' If tabno = 49 Or tabno = 50 Or tabno = 51 Then
nextrow = nextrow + 1
Set rng = Worksheets("Sheet2").Range("B" & nextrow)

rng.Offset(, -1) = "Table " & tabno
'Set Table = d.all.tags("Table").Item(4)
For Each r In t.Rows
For Each c In r.Cells
rng.Value = c.innerText
Set rng = rng.Offset(, 1)
i = i + 1
Next c
nextrow = nextrow + 1
Set rng = rng.Offset(1, -i)
i = 0
Next r
' End If
End If
Next e

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,114,052
Messages
5,545,734
Members
410,702
Latest member
clizama18
Top