我在使用selenium选择此软件中的RUC选项时遇到问题,标签不包含区分它们的ID,并且类是相同的:
我正在使用以下代码,但它不适用于我:
label_tipo_documento = driver.find_element_by_xpath('//div[@id="form-group-tipo_documento"]//div[@class="col-sm-3"]//label[@class="radio-inline"][2]')
print(label_tipo_documento.text)
label_tipo_documento.click()
我尝试在标签[2](RUC)中选择第二个选项,并收到以下消息:
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@id="form-group-tipo_documento"]//div[@class="col-sm-3"]//label[@class="radio-inline"][2]"}
(Session info: chrome=87.0.4280.88)
但是,当我使用[1]而不是[2]执行此操作时,它会找到一个值:
DNI
意味着您要选择
div
node的第二个子体标签(它只有一个子体标签)。而您需要选择标签的第二次出现次数。所以要么试试或
要单击与文本关联的元素作为RUC,您可以使用以下任一Locator Strategies:
对
<input>
使用css_selector
:使用
xpath
和<label>
文本:理想情况下,要单击元素,您需要为
element_to_be_clickable()
诱导WebDriverWait,并且可以使用以下Locator Strategies之一:使用
CSS_SELECTOR
:使用
XPATH
:注意:您必须添加以下导入:
参考资料
你可以在以下网站上找到关于NoSuchElementException的一些相关讨论:
使用下面的
xpath
单击第二个单选按钮如果你想使用索引,那么试试下面的代码
相关问题 更多 >
编程相关推荐