Jump to content
UBot Underground

Xpath Select Multiple Radio Buttons With Same Text


Recommended Posts

Hi,

I'm attempting to select multiple radio buttons (with the same text), using xpath.

The html is like this:

<input type="radio" class="site-form-field" name="850_4750" id="850_4750_216808" value="#216808">
 <label for="850_4750_216808" class="site-form-label inline">Not applicable</label>
 

This command selects the 1st instance of 'Not applicable' but does not select the rest:
 

plugin command("ExBrowser.dll", "ExBrowser Click", "x://label[contains(text(),\"Not applicable\")]")


How should I construct the xpath so that it selects ALL radio buttons marked 'Not applicable' and not just the first one?
 

Link to post
Share on other sites

Hi,

 

I'm attempting to select multiple radio buttons (with the same text), using xpath.

 

The html is like this:

<input type="radio" class="site-form-field" name="850_4750" id="850_4750_216808" value="#216808">
 <label for="850_4750_216808" class="site-form-label inline">Not applicable</label>
 

This command selects the 1st instance of 'Not applicable' but does not select the rest:

 

plugin command("ExBrowser.dll", "ExBrowser Click", "x://label[contains(text(),\"Not applicable\")]")

How should I construct the xpath so that it selects ALL radio buttons marked 'Not applicable' and not just the first one?

 

 

The problem here is not the Xpath. Your Xpath Expression will actually select all the elements correctly.

But the ExBrowser Click Command can only click one element at a time. And if the Xpath Expression you use has multiple matches, it will click the first one.

 

So the solution is, you click one at a time. With Xpath Offsets. 

You learn all that in my Xpath tutorials:

http://www.bot-factory.com/xpath-video-tutorials/

 

But here's a quick tip:

(//label[contains(text(),"Not applicable")])[1]

 

Dan

  • Like 1
Link to post
Share on other sites
  • 2 months later...

@op where you able to do it?

 

I do not mean to jack your thread... but...

 

Dan, Can you please elaborate a little bit more about your tip?

 

i tried it and it only clicks the corresponding number...

 

I also have it on a loop... but then again... the button that keeps getting clicked is the number inside [number_here]

 

I also do not think it is possible to put the [number_here] into a variable and increment it... on each loop...

 

please help... i am running out of hair... been pulling them all day long...

Link to post
Share on other sites

broad selector

x://label[contains(text(),"Not applicable")]

 

This one selects the first one available

x:(//label[contains(text(),"Not applicable")])[1]

 

This one selects the second one available

x:(//label[contains(text(),"Not applicable")])[2]
 

Note the formatting and the 1 and 2 at the end in brackets and the ( and ) around the main selector

this is like offsets.  but start at 1
 

 

 

 

Link to post
Share on other sites

thanks TJ,

 

I was actually trying to increment that 

 

x:(//label[contains(text(),"Not applicable")])[1]

 

For those guys who might need it:

 

here's what I got from Dan:

 

plugin command("ExBrowser.dll", "ExBrowser Click", "x:(//a)[{#counter}]")

 

just set the variable and there it goes...
 

Thanks Dan and Tj
 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...