0

I am trying to automate the downloading of an excel file. This is my first time using selenium and i don't normally code in Python so maybe a bit of a basic question.

I have got a login in and ticking a checkbox working, but the second to last step which is clicking a download button which seems to be a . I have looked around stack overflow and google i can find similar problems but i can not find a solution that fixes my problem. I am normally using

.find_element_by_xpath

Which works for everything else but not the download button. I have added a wait to make sure page is fully loaded but it does not make it any easier.

#Downlod checked Catalogue
CatDownloadBtn = driver.find_element_by_xpath('/html/body/div[3]/form/div[2]/input[1]')
CatDownloadBtn.click()

I have tired the xpath and full xpath neither worked.

I am getting the following error.

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (213, 17). Other element would receive the click: ...

enter image description here

The Inspector -> Element as in code.

<div class="col-md-offset-0 col-md-10 downloadBtn">
        <input name="submit" type="submit" class="btn btn-default" value="Download Catalogues">
        <input name="submit" type="submit" class="btn btn-default" value="Download Attributes">
        <input name="submit" type="submit" class="btn btn-default" value="Download Enhanced Data">
</div>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
PhilWilky
  • 1
  • 3

5 Answers5

0

This normally happens because the element your trying to click is not clickable, there are multiple 'building blocks' to make a working element, this error normally occurs because your trying to click the wrong 'block'.

A way to combat this is to try clicking different elements, either going up a level or further down, I think in your case it's supposed to be further up since 'input' normally isn't clickable.

Since I don't know what the website is, I can't give specifics

Salman B
  • 138
  • 11
0

Indicates that a click could not be properly executed because the target element was obscured in some way.

Try JS script sample like below

ele = driver.find_element_by_xpath("//input[@class='button']")
driver.execute_script("arguments[0].click();", element)

Also if does not work try with waits

wait.until(ExpectedConditions.elementToBeClickable(element));

ASin
  • 106
  • 1
  • 4
0

ElementClickInterceptedException is an exception which occurs when some other element comes in front of another or something which would prevent a real human click (e.g. when you need to scroll down). There are few solutions you can try.

Solution 1 (Javascript executer):

CatDownloadBtn = driver.find_element_by_xpath('/html/body/div[3]/form/div[2]/input[1]')
driver.execute_script('arguments[0].click()', CatDownloadBtn) # Performs a Javascript click

Solution 2 (Make sure element does not get intercepted):

You can check if there is a need to scroll down before clicking.

driver.execute_script("window.scrollTo(0, Y)") # Y is the height

Extra:

Button can be selected by value using:

CatDownloadBtn = driver.find_element_by_xpath('//input[@value="Download Catalogues"]')
Ali Sajjad
  • 3,589
  • 1
  • 28
  • 38
  • Hi Ali Sajjad, thanks for your help. I think it due to having to scroll down the page to check the checkbox. So i think i might need to get the view back to the top of the website. – PhilWilky Jun 30 '20 at 18:03
  • @PhilWilky If you don't want to scroll or don't really need to make selenium script human like, then using the javascript must solve the problem :-) Did you try that? – Ali Sajjad Jun 30 '20 at 18:09
0

To click on the <input> element with text as Download Catalogues you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR and submit():

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.downloadBtn>input[value='Download Catalogues']"))).submit()
    
  • Using XPATH and click():

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(@class, 'downloadBtn')]/input[@value='Download Catalogues']"))).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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Hi DebanjanB, Thanks for helping out. Using CSS_SELECTOR and submit(): i get selenium.common.exceptions.JavascriptException: Message: javascript error: arguments[0].submit is not a function Using XPATH and click(): selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (213, 17). Other element would receive the click: ... Am i doing something wrong? – PhilWilky Jun 30 '20 at 18:18
  • @PhilWilky How about the _xpath_? – undetected Selenium Jun 30 '20 at 19:32
0

Hello thanks for all your help and solutions really appreciate everyone's time. So i managed to solve this using the following.

from selenium.webdriver.common.keys import Keys

Then before CatDownloadBtn i use control + home to get to the top of the page.

#Go back to the top of the page
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.HOME)

So my full snippet would look like this.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()

#Go back to the top of the page
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.HOME)

#Downlod checked Catalogue
CatDownloadBtn = driver.find_element_by_xpath('/html/body/div[3]/form/div[2]/input[1]')
CatDownloadBtn.click()
PhilWilky
  • 1
  • 3