1

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

2

1 Answer 1

1

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
6
  • That was going to be my other attempt - try using label name in the css. I do see in the source code that these are of the type radio:{<input data-v-2b1acfa4="" tabindex="0" role="radio" type="radio" name="moveTypeRadios" value="INDIVIDUAL" class="radio-cards__input">}
    – joiner
    Commented Apr 5, 2020 at 22:19
  • And just curious, which start URL did you use? It usually always goes to "...mgo/disclaimer" or "...mgo-m/disclaimer" on my end. The other link is using the header which is likely for tracking such as "...mgo/disclaimer?referral=MG80"
    – joiner
    Commented Apr 5, 2020 at 22:27
  • I looked at moversguide.usps.com/mgo-m/move-combined as start url. I forgot to include that (Sorry). For the radion html you show - yes, you could have tried [type=radio][value=" & val & "]" - I didn't see that as the expected interactable part of the page which are the label elements.
    – QHarr
    Commented Apr 6, 2020 at 6:02
  • Thank you. Yes, I have used this URL and it's simpler to interact with (haven't seen a reCaptcha on this page so far). There's another issue that I am running into on this page. When it comes to selecting the date fields, the desktop ('...mgo/disclaimer") version can have the date sent directly to the input box using sendkeys. Any guidance you can provide on how to accomplish this on the mobile version (",,,mgo-m/move-combined')? In the meantime, I am going to fiddle and research how to click on the date with such pop-up calendar buttons on the mgo-m page
    – joiner
    Commented Apr 6, 2020 at 13:02
  • You could stick with your current initial url and still use the same idea for clicking the labels. Then you can carry on with your sendkeys for date fields. I will have a look at the appropriate method using the start url I gave in comments. It sounds like it is the more fiddly spinner up/down clicking type where you click an up/down until target value achieved.
    – QHarr
    Commented Apr 6, 2020 at 13:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.