简体   繁体   English

硒/ python-无法单击元素

[英]Selenium / python - cannot click on an element

I am trying to use python and selenium to go to a website to collect some data, but I can't even get past the initial popup asking me to click an Accept button to agree to the terms of use! 我正在尝试使用python和硒去网站收集一些数据,但是我什至无法跳过最初的弹出窗口,要求我单击“接受”按钮以同意使用条款! The website is here 网站在这里

I can see that the 'Accept' link/div has an id and I've tried using find_element_by_xpath and selecting the id then attempting to click, but that doesn't work. 我可以看到“ Accept”链接/ div具有一个ID,并且我尝试使用find_element_by_xpath并选择该ID,然后尝试单击,但这是行不通的。

I've also tried using ActionChains to navigate to the button and clicking, but that doesn't work either. 我也尝试过使用ActionChains导航到该按钮并单击,但这也不起作用。 The error it returns is element is not clickable at point... 它返回的错误是元素不可点击...

There appears to be some jquery/javascript going on in the background which is proving difficult to deal with! 似乎有一些jquery / javascript在后台进行,事实证明很难处理!

Any help would be greatly appreciated. 任何帮助将不胜感激。

The trick is to wait for the "Accept" button to become clickable , move to the button and click: 诀窍是等待“接受”按钮变为可点击状态 ,移至该按钮并单击:

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


driver = webdriver.Firefox()
driver.get("https://www.etfsecurities.com/institutional/uk/en-gb/products.aspx")

wait = WebDriverWait(driver, 10)
accept = wait.until(EC.element_to_be_clickable((By.ID, "btnPopupAccept")))

actions = ActionChains(driver)
actions.move_to_element(accept).click().perform()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM