python - 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:消息:没有这样的元素:无法找到元素
有人可以帮忙吗?谢谢
解决方案
您必须接受页面底部显示的 cookie
driver.find_element_by_xpath("//a[@id='btn_accept_cookies']").click()
推荐阅读
- javascript - 在JS中将字符串字母转换为不同的字母
- sql - SQL - 为第 1 列中的每个不同值添加一个总行
- react-native - 在 react-native-google-places-autocomplete 中,有一种设置输入初始值的方法,但它不会触发搜索查询
- javascript - 使用 React 测试库/WaitFor 进行异步测试
- python - Python:如何转换内存中的图像?
- javascript - 如何修改 React Native 的 TextInput 组件中文本的显示方式?
- sql - 如果 Varchar 超过 999,则算术溢出错误,为什么?
- reactjs - 在抽屉组件底部添加项目
- npm - npm install 的区别
和 npm 安装 @最新的 - filtering - Docusign REST API 调用:对 search_text 使用逻辑运算符