问题
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?
回答1:
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/
回答2:
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']
来源:https://stackoverflow.com/questions/28610407/selenium-webdriver-python-cannot-find-by-value