python-3.x - Selenium xpath Webelement问题
问题描述
我对硒有点陌生,所以请原谅我的无知。我正在尝试从网站获取 ajax 加载表的行。代码看起来像这样:
try:
table = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "tableid")))
finally :
for row in table.xpath(".//tr"):
print(row)
但是,我收到以下错误:
AttributeError: 'WebElement' object has no attribute 'xpath'
让我知道错误是什么
解决方案
此错误消息...
AttributeError: 'WebElement' object has no attribute 'xpath'
...意味着您的程序已尝试调用不可xpath
用的属性。
解决方案
WebElement没有属性为xpath
. 相反,您可能喜欢调用find_element_by_xpath()
方法。因此,您必须有效地更改线路:
for row in table.xpath(".//tr"):
和:
for row in table.find_elements_by_xpath("./tr"):
推荐阅读
- ruby - 形状移出窗口区域
- python - 我想找到我拥有的数字的总和
- wolfram-mathematica - Mathematica - 将变量定义为正数和实数
- javascript - Angular:检查元素是否有一个类并将一个类添加到另一个元素
- python - 如何将ttk.Notebook框架配置为平面浮雕?
- mongodb - 猫鼬查询没有完全填充
- python - 使用 Keras、Python 校正 CNN、基于 LSTM 的分类器的输入尺寸
- c# - 对于混合身份验证,ConfigureAuth 设置应该是什么?(标准登录页面和 OpenId 挑战)
- multithreading - 重新启动 TEvent.WaitFor 而不退出它
- java - 没有可用于当前线程的具有实际事务的 EntityManager - 无法可靠地处理“持久”