您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

AttributeError:“列表”对象使用Selenium和Python没有属性“单击”

AttributeError:“列表”对象使用Selenium和Python没有属性“单击”

我仍然建议您通过 /html/body/div[5]/section/div[8]/div[1]/a[1] ****

因此,代替此 :

elm = driver.find_elements_by_xpath("/html/body/div[5]/section/div[8]/div[1]/a[1]").click()

试试这个代码

annual_link = driver.find_element_by_link_text('Annual')
annual_link.click()

是的@Druta是正确的,find_element用于一个Web元素和Web元素find_elements列表。拥有总是很好explicit wait

创建显式等待的实例,如下所示:

wait = webdriverwait(driver,20)

并使用如下的等待引用:

wait.until(EC.elementToBeClickable(By.LINK_TEXT, 'Annual'))

from selenium import webdriver
link = 'https://www.investing.com/equities/apple-computer-inc-balance-sheet'

driver = webdriver.Firefox()
driver.maximize_window()
wait = webdriverwait(driver,40)
driver.get(link)

driver.execute_script("window.scrollTo(0, 200)")

wait.until(EC.element_to_be_clickable((By.LINK_TEXT, 'Annual')))
annual_link = driver.find_element_by_link_text('Annual')
annual_link.click()
print(annual_link.text)

确保导入这些:

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import webdriverwait
from selenium.webdriver.support import expected_conditions as EC
python 2022/1/1 18:26:18 有553人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶