【问题标题】:AttributeError: 'list' object has no attribute 'find_element' - Selenium driverAttributeError: \'list\' 对象没有属性 \'find_element\' - Selenium 驱动程序
【发布时间】:2023-01-27 21:43:10
【问题描述】:

我正在重写这个使用旧版本 Selenium 的旧 pyton 脚本 (https://github.com/muvvasandeep/BuGL/blob/master/Scripts/DataExtraction.py)。这个脚本的目的是从 github 的开源项目中提取开放和关闭的问题。我是 python 和 Selenium 的新手。我很难重写里面的几件事。目前我正在努力让这个工作:

repo_closed_url = [link.get_attribute('href') for link in driver.find_elements(By.XPATH,'//div[@aria-label="Issues"]').find_element(By.CLASS_NAME,'h4')]

上面应该从 github 页面获取所有已关闭的问题链接并将其存储在 repo_closed_url 数组中。但我收到 AttributeError: 'list' object has no attribute 'find_element' 错误。请帮忙。

【问题讨论】:

  • 发生此错误是因为您正在尝试将 .find_element 用于列表。尝试获取驱动程序的数据类型

标签: python selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

find_elements 返回一个列表,并且列表没有方法 find_element(根据您的错误消息)。

您可以将 find_element 方法移动到 link

repo_closed_url = [link.find_element(By.CLASS_NAME,'h4').get_attribute('href') for link in driver.find_elements(By.XPATH,'//div[@aria-label="Issues"]')]

这似乎更像是您要尝试做的事情,而不是迭代单个元素。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-17
    • 1970-01-01
    • 1970-01-01
    • 2012-06-28
    • 1970-01-01
    • 2023-04-09
    相关资源
    最近更新 更多