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
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
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?
 
Upvote 0
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?
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,396
Messages
6,119,268
Members
448,881
Latest member
Faxgirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top