Noa*_*iff 5 selenium xpath python-3.x selenium-webdriver
我在硒中有以下代码,但继续出现语法错误。我试图根据多个条件选择一个元素。
choices = driver.find_elements_by_xpath("//div[contains(.,'5') and [contains(@class, 'option')]]")$
Run Code Online (Sandbox Code Playgroud)
谢谢你提供的所有帮助。
按照您共享的xpath如下:
choices = driver.find_elements_by_xpath("//div[contains(.,'5') and [contains(@class, 'option')]]")$
Run Code Online (Sandbox Code Playgroud)
您需要考虑一些事实:
<div>标记的多个条件不能在嵌套中[]。您必须在1个[]或多个内指定[]。$您可以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')]")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3029 次 |
| 最近记录: |