python-3.x - 如何在 selenium python 中修复这个 xpath?
问题描述
我对这个 python 和 selenium 世界很陌生。尝试使用 selenium webdriver 用 python 自动化一些无聊的东西。我在xpath下面遇到问题。似乎"="
把事情搞砸了。
有人可以帮忙吗?
L = driver.find_element_by_xpath("//*[@id="ext-comp-1016"]/div[1]/table/tbody/tr/td[2]/div[1]").click()
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="ext-comp-1016"]/div[1]/table/tbody/tr/td[2]/div[1]"}
(Session info: chrome=87.0.4280.66)
解决方案
检查 xpath 是否在 DOM 页面上正常工作。
如果 xpath 是正确的,我建议使用隐式等待方法。可能运行的脚本比 DOM 页面加载更快。
from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC L = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.Xpath,"/div[1]/table/tbody/tr/td[2]/div[1]"))).click()
推荐阅读
- arrays - 将字符串转换为具有变量名的对象
- hibernate - 在双向一对多映射中设置级联
- app-store-connect - ITMS-90424:无效的 Swift 支持
- python-3.x - 在 python 3 中实现洋葱代理
- c++ - 使用 cygwin 编译 C++/SDL2/OpenGL 项目
- c - 我不明白如何解释 ++a * ++a
- java - 将变量从活动传递到片段时的空对象引用
- python - 无法从 python 脚本启动 docker log 命令
- ios - 导航控制器未插入某些 ViewController
- cmd - 如何在我的 jhister 应用程序中导入我的 file.jh