我在 selenium 中有以下代码,但仍然出现语法错误。我正在尝试根据多个条件选择一个元素。
choices = driver.find_elements_by_xpath("//div[contains(.,'5') and [contains(@class, 'option')]]")$
谢谢你提供的所有帮助。
根据xpath您分享如下:
choices = driver.find_elements_by_xpath("//div[contains(.,'5') and [contains(@class, 'option')]]")$
您需要考虑一些事实:
- 多重选择条件
<div>
标签不能嵌套在标签内[]
。您必须在一个范围内指定[]
或多个内[]
s.
- The xpath不应以不需要的字符结尾,例如
$
Solution
你可以重写xpath
通过以下任一方式:
choices = driver.find_elements_by_xpath("//div[contains(.,'5') and contains(@class, 'option')]")
# or
choices = driver.find_elements_by_xpath("//div[contains(.,'5')][contains(@class, 'option')]")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)