Selenium无法使用Python单击“获取数据"按钮 [英] Selenium not able to click on Get Data button on using Python

查看:41
本文介绍了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()">

但是无法让硒点击它甚至尝试了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?

推荐答案

要单击元素获取数据,可以使用以下任一

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

  • 理想情况下,要单击该元素,您需要诱导定位器策略:

    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单击“获取数据"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆