【发布时间】:2021-03-11 13:19:05
【问题描述】:
我正在尝试使用 Selenium 访问此网站上的“下载 csv”按钮。 https://fplreview.com/team-planner/#forecast_table。当我第一次点击该网站时,我需要输入一个“团队 ID”并点击提交,这很好,但随后会出现一个弹出广告,我无法关闭它。我尝试了一些主要使用 XPATH 的方法,但它说按钮不存在,尽管我添加了一个睡眠计时器来等待页面加载等。我的最终目标是使用请求来做到这一点,但我正在尝试让它工作首先使用硒。谢谢。下面是我的代码
`
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://fplreview.com/team-planner/#forecast_table')
team_id = driver.find_element_by_name('TeamID')
team_id.send_keys(123)
team_id.submit()
# click close button on ad.
ad_path = '//*[@id="butt"]/html/body/div[2]/div[3]/div/div/div/div[1]/div/article/div[2]/div/div[18]/div/div/div[3]/button'
button = driver.find_element_by_xpath(ad_path)
button.click()
# export csv
export_button = driver.find_element_by_id('exportbutton')
export_button.click()
driver.quit()
`
由此产生的错误
`
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="butt"]/html/body/div[2]/div[3]/div/div/div/div[1]/div/article/div[2]/div/div[18]/div/div/div[3]/button"}
`
【问题讨论】: