【问题标题】:Selenium / python - cannot click on an elementSelenium / python - 无法单击元素
【发布时间】:2016-07-09 21:08:08
【问题描述】:

我正在尝试使用 python 和 selenium 访问网站以收集一些数据,但我什至无法超越最初的弹出窗口,要求我单击接受按钮以同意使用条款!网址是here

我可以看到“接受”链接/div 有一个 id,我尝试使用 find_element_by_xpath 并选择 id 然后尝试点击,但这不起作用。

我也尝试过使用 ActionChains 导航到按钮并单击,但这也不起作用。它返回的错误是 element is not clickable at point...

似乎有一些 jquery/javascript 在后台运行,事实证明这很难处理!

任何帮助将不胜感激。

【问题讨论】:

    标签: jquery python selenium selenium-webdriver


    【解决方案1】:

    诀窍是等待“接受”按钮变为可点击,移动到按钮并点击:

    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()
    

    【讨论】:

    • 谢谢!!完美运行!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 2019-04-13
    • 1970-01-01
    • 1970-01-01
    • 2017-07-25
    相关资源
    最近更新 更多