1

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

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?

Zac
  • 181
  • 1
  • 8
  • Could also be you are going to fast for selenium. There are commands to help you with this. See the [doc](https://selenium-python.readthedocs.io/waits.html) – tgrandje Dec 04 '20 at 08:36

2 Answers2

2

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

  • Using css_selector:

    driver.find_element_by_css_selector("img.getdata-button#get").click()
    
  • Using 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:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "img.getdata-button#get"))).click()
    
  • Using 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
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • Sorry but its not working, please have a look at my code which i have update in my question. Do fix my code if possibe – Zac Dec 04 '20 at 17:12
0

You should probably try by id

driver.find_element(By.ID, 'get').click()
Crapy
  • 254
  • 1
  • 8