首页 > 解决方案 > Python/Selenium - 单击按钮

问题描述

我试图让 Selenium 点击一个按钮来点击一个链接(它是表格下方的“上个月”按钮): https ://www.interactivebrokers.eu/en/index.php?f=39108

我尝试了以下

from selenium import webdriver

url = 'https://www.interactivebrokers.eu/en/index.php?f=39108'

driver = webdriver.Chrome("C:\\Users\\domen\\anaconda3\\Lib\\site-packages\\chromedriver_py\\chromedriver_win32.exe")

driver.get(url)
button = driver.find_element_by_css_selector('#monthly-interest-rates > div > div > div > div:nth-child(5) > a.btn.btn-sm.btn-default')
button.click()

但我收到以下错误:ElementClickInterceptedException:消息:元素单击被拦截:元素 ... 在点 (367、916) 处不可单击。其他元素会收到点击:...

我遇到了同样的错误:

button = driver.find_element_by_link_text("Previous Month").click()

我还尝试了以下两种选择:

button = driver.find_element_by_xpath('/html/body/div[3]/section[2]/div/div/div/div[2]/a[1]')
button = driver.find_element_by_class_name('btn btn-sm btn-default')

但我得到:NoSuchElementException:消息:没有这样的元素:无法找到元素

有人可以帮忙吗?谢谢

标签: pythonpython-3.xseleniumselenium-webdriverweb-scraping

解决方案


您必须接受页面底部显示的 cookie

driver.find_element_by_xpath("//a[@id='btn_accept_cookies']").click()

推荐阅读