How do I click on a radio button on the webpage in a form? I am trying to write a code to automate form filling with Excel VBA. Here is the problem statement: Need to click on one of the three options on the page "https://moverguide.usps.com/mgo/disclaimer" or https://moversguide.usps.com/mgo-m/disclaimer namely "Individual", "Family" and "Business", I get the following error:
Run time error 11: NoSuchElementErrorElement Cannot click on element
when I use this sample code:
If var = individual or family or business Then
If obj.FindElementById("move-type-var").IsPresent Then
obj.FindElementById("move-type-var").Click
End If
or this error:
Runtime error 7
NoSuchElementError
when I run the following sample code:
if condition satisfied then
obj.FindElementByCss ("css=.row--reskin:nth-child(1) .reskin__card:nth-child(1) > .reskin__card--label)")
End If
I obtained the css parameter by extracting the css target from Firefox. Basically, I recorded a script using Selenium IDE to see what exactly is happening so that I leverage appropriate target value for my Excel VBA solution.
One of the properties in the IE console (F12) when I manually check the source code is "aria-checked" set to checked/true. This happens when I click on one of the options myself. Is that what I have to enable in the code?
Just a disclaimer: Good with Excel VBA overall but exploring webforms and quite new to this aspect.
Tools: Selenium webdriver for IE11, MS Excel (office 365), VBA
They are labels not radio buttons. You can target with css attribute = value selectors; where you concatenate the option string of interest into the for
attribute value. I use a slightly different start url to avoid unnecessary steps.
Dim var As String
'individual, family, business
var = "business"
obj.findElementByCss("[for='move-type-" & var & "']").Click