2

I'm trying to select one of three checkboxes on a page but the source code for them looks like this:

<input type="radio" name="Option" value="1">
<input type="radio" name="Option" value="2">
<input type="radio" name="Option" value="3">

So the only thing differentiating them is value, but there is no find_element_by_value. How would I go about switching between these 3 checkboxes?

2 Answers 2

8

You can use xpath for identification of elements in such cases,

browser.find_element_by_xpath("//input[@value='1']")

For a better understanding of how xpaths work, you can refer the below link http://www.toolsqa.com/selenium-webdriver/choosing-effective-xpath/

Sign up to request clarification or add additional context in comments.

Comments

0

I will use cssSelector to identify this. There is no mechanism to find the element by value. Use find_element_by_css_selector with the following selector. Refer the api

input[value='3']

or, to be more precise

input[value='3'][type='radio']

Changing the value would definitely let you grab what you need.

Also, possible to use xpath with find_element_by_xpath for this

//input[@value='2']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.