Selenium Webdriver Python,无法按值查找?
问题描述:
我正在尝试选择页面上的三个复选框之一,但是它们的源代码如下:
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">
因此区别它们的唯一是值,但是没有find_element_by_value.我将如何在这三个复选框之间切换?
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?
答
在这种情况下,您可以使用xpath标识元素,
You can use xpath for identification of elements in such cases,
browser.find_element_by_xpath("//input[@value='1']")
要更好地了解xpaths的工作原理,可以参考以下链接 http://www.toolsqa.com/selenium-webdriver/choosing-effective- xpath/
For a better understanding of how xpaths work, you can refer the below link http://www.toolsqa.com/selenium-webdriver/choosing-effective-xpath/