小编yuz*_*hen的帖子

TypeError:无法对“文档”执行“评估”:结果不是节点集,因此无法通过 Selenium 使用 Xpath 进行转换

部分页面来源:

<span style="display:block; overflow:hidden; white-space: nowrap">Gi2/0/20</span>
Run Code Online (Sandbox Code Playgroud)

部分代码:

from selenium import webdriver
...
driver = webdriver.Chrome()
...
IP_CLICK = browser.find_element_by_xpath('//span[@style="display:block; overflow:hidden; white-space: nowrap"]/text()="Gi2/0/20"').click()
Run Code Online (Sandbox Code Playgroud)

我尝试使用表达式在网页中选择一个元素xpath,但出现以下错误:

InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //span[@style="display:block; overflow:hidden; white-space: nowrap"]/text()="Gi2/0/20" because of the following error:
Run Code Online (Sandbox Code Playgroud)

TypeError:无法对“文档”执行“评估”:结果不是节点集,因此无法转换为所需的类型。(会话信息: chrome=72.0.3626.121) (驱动程序信息: chromedriver=73.0.3683.20 (8e2b610813e167eee3619ac4ce6e42e3ec622017),platform=Windows NT 6.1.7601 SP1 x86_64)

python selenium xpath xpath-1.0 selenium-webdriver

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

python ×1

selenium ×1

selenium-webdriver ×1

xpath ×1

xpath-1.0 ×1