【问题标题】:Selenium xpath Webelement issueSelenium xpath Webelement问题
【发布时间】:2020-07-24 01:38:06
【问题描述】:

我对硒有点陌生,所以请原谅我的无知。 我正在尝试从网站获取 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'

告诉我错误是什么

【问题讨论】:

    标签: python-3.x selenium selenium-chromedriver


    【解决方案1】:

    此错误消息...

    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"):
    

    【讨论】:

    • 嗨,这不适用于./tr 我收到错误没有这样的元素:无法找到元素:{“method”:“xpath”,“selector”:“./tr "}
    • @kiteshjain 修复了一个小错误,重新测试并告诉我状态。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-01
    • 1970-01-01
    • 2016-10-01
    • 1970-01-01
    • 2014-08-16
    • 1970-01-01
    • 2017-11-17
    相关资源
    最近更新 更多