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

Community
  • 1
  • 1
joiner
  • 47
  • 1
  • 2
  • 11

1 Answers1

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
QHarr
  • 83,427
  • 12
  • 54
  • 101
  • 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:{} – joiner Apr 05 '20 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 Apr 05 '20 at 22:27
  • I looked at https://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 Apr 06 '20 at 06: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 Apr 06 '20 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 Apr 06 '20 at 13:36
  • I literally went through many of your feedbacks on other questions to find a solution. Nothing from the solutions out there seem to work on this (mgo-m) page properly to set the right date. Were you to be look into it? I am more inclined to using the mgo-m page as it does not really give me the captcha so would prefer to find a solution that works on this page. If you weren't able to that's okay too. Thought will give a shout. – joiner Apr 07 '20 at 02:39