Selenium 在使用 Python 时无法单击“获取数据"按钮

Selenium not able to click on Get Data button on using Python(Selenium 在使用 Python 时无法单击“获取数据按钮)
本文介绍了Selenium 在使用 Python 时无法单击“获取数据"按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在从这个网站上抓取数据.元素在下面和geckodriver

I am scraping data from this website . The element is below and geckodriver

<img class="getdata-button" style="float:right;" src="/common/images/btn-get-data.gif" id="get" onclick="document.getElementById('submitMe').click()">

但无法让 selenium 单击它甚至尝试了 xpath、id 但不是运气是否有任何修复或解决方法来完成它?

but can't get selenium to click it tried even xpath, id but not luck is there any fix or work around to get it done?

推荐答案

要点击元素 Get Data,您可以使用以下任一 定位器策略:

To click on the element Get Data you can use either of the following Locator Strategies:

  • 使用 css_selector:

driver.find_element_by_css_selector("img.getdata-button#get").click()

  • 使用 xpath:

    driver.find_element_by_xpath("//img[@class='getdata-button' and @id='get']").click()
    

  • 理想情况下,点击你需要诱导的元素 WebDriverWait 用于 element_to_be_clickable() 并且您可以使用以下任一 定位器策略:

    Ideally, to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

    • 使用 CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "img.getdata-button#get"))).click()
    

  • 使用 XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//img[@class='getdata-button' and @id='get']"))).click()
    

  • 注意:您必须添加以下导入:

  • Note: You have to add the following imports :

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

  • 这篇关于Selenium 在使用 Python 时无法单击“获取数据"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

    本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

    相关文档推荐

    groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
    Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
    Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
    Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
    Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
    Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)