“不是有效的xpath表达式”selenium python

2024-06-28 11:57:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用xpath表达式在我的网页中选择一个元素。在

这是代码的基本部分

from selenium import webdriver
...

driver = webdriver.Chrome()
...

xpath = "//select[@onchange='onCodeChanged('14', this);']/option[text()='CPT 99429']"
e = driver.find_element_by_xpath(xpath)
e.click()

我要选择的部分页面源:

^{pr2}$

错误:

SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//select[@onchange='onCodeChanged('14', this);']/option[text()='CPT 99429']' is not a valid XPath expression.

我有一种感觉,这与引号或;符号有关,因为我已经成功地使用了同样的方法在网页中选择元素,但是现在得到了这个错误。在


Tags: text元素网页表达式driver错误thisselect