Error encountered: Element not clickable - The attempt to click on a download link was interrupted due to the element being intercepted

When using Selenium and Python, I am working on automating the process of clicking on targets.simple.csv to download a .csv file from the following page:

This is the code snippet I have written:

import pandas as pd
import numpy as np
from datetime import date
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
import time

chromedriver_path = r"./driver/chromedriver"
browser = webdriver.Chrome(executable_path=chromedriver_path)
url = "https://www.opensanctions.org/datasets/default/"
topics_xpath = '/html/body/div[1]/div/div/div[1]/section[2]/table/tbody/tr[6]/td[2]/a/code'
browser.get(url)
browser.maximize_window()
time.sleep(10)  #Wait for the page to load.
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[1]/div[2]/div/div/div[2]/div/button[1]"))).click()
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[1]/div/div/div[1]/section[2]/table/tbody/tr[6]/td[2]/a/code"))).click()

However, when running the script, I encounter this error message:

ElementClickInterceptedException: element click intercepted: Element is not clickable at point (360, 1282)
  (Session info: chrome=114.0.5735.198)

Interestingly, I do not face this error when:

  • I manually scroll to the location of the downloadable csv file as soon as the page loads

If I manually scroll, the code successfully downloads the .csv file. Is there a way in Python to automate scrolling to the desired file for download?

Answer №1

For those looking for code references, the documentation can be found at https://www.selenium.dev/documentation/webdriver/actions_api/wheel/#scroll-to-element

perform() function moves down one step at a time until it reaches the specified href, breaking the loop as needed.

from_viewport() is used to identify the initial coordinates on the screen.

kkk_y = int(kkk.rect['y']) retrieves the y coordinate of the element.

The following code snippet demonstrates how to scroll to a specific element:

ActionChains(driver).scroll_from_origin(scroll_origin, 0, kkk_y).perform()

As I did not have Chrome and driver installed, I opted to use Edge.

Sample code blocks are provided below...

Additional Information

It's advisable to fetch website data using the requests library instead of relying solely on click actions. This alternative approach is demonstrated by downloading a file named targets.simple.csv.

More code samples await your exploration... 

Answer №2

To interact with the interactive element, you must first scroll down a bit and employ WebDriverWait to ensure the element_to_be_interactive(). You can opt for any of these locator techniques:

  • Utilizing PARTIAL_LINK_TEXT:

    browser.get("https://www.opensanctions.org/datasets/default/")
    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[class^='Analytics_consentButtons'] button.btn.btn-secondary"))).click()
    browser.execute_script("scroll(0, 1000);") # Scroll Down
    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "targets.simple.csv"))).click()
    
  • Using CSS_SELECTOR:

    browser.get("https://www.opensanctions.org/datasets/default/")
    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[class^='Analytics_consentButtons'] button.btn.btn-secondary"))).click()
    browser.execute_script("scroll(0, 1000);") # Scroll Down
    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href*='targets.simple.csv'] > code"))).click()
    
  • Employing XPATH:

    browser.get("https://www.opensanctions.org/datasets/default/")
    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[class^='Analytics_consentButtons'] button.btn.btn-secondary"))).click()
    browser.execute_script("scroll(0, 1000);") # Scroll Down
    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//a/code[text()='targets.simple.csv']"))).click()
    
  • Note: Remember to import the following:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Choose a selection of n values from a list that covers the entire range

I need to choose n values evenly spaced from a given list of numbers. For instance: vals = list(range(10)) select_n(vals, 4) select_n(vals, 5) should result in [0, 3, 6, 9] [0, 2, 5, 7, 9] The current method I use involves iterating like this: [vals[ ...

What is the best way to update the value of a specific key in a JSON object retrieved through an API call made with requests.get?

Issue Overview: I have encountered a problem while working with an API using the requests.get method. Upon receiving the JSON object, I store it in a variable as a JSON dictionary: data = json.loads(response.text) My objective is to access this dictiona ...

What is the best way to keep an HTML element visible on the page while it remains within the boundaries of another HTML object?

On my webpage, I have a selection of reports available. Currently, there are 4 sizable buttons located on the right-hand side for viewing, adding, editing, or deleting a report. However, there have been complaints from users who find it inconvenient to scr ...

When using the method find_element_by_css_selector('a').get_attribute('href'), a NoSuchElementException is returned if the element cannot be found

I have been attempting to scrape product links from a specific website using my program. The process involves opening the necessary URL in the browser and extracting all the links with a particular class name. However, I keep encountering a NoSuchElementEx ...

Python allows for the retrieval of the aria-label attribute as text based on the div id with the help of libraries like Beautiful Soup

<div id="i19" class="quantumWizTogglePapercheckboxEl appsMaterialWizTogglePapercheckboxCheckbox docssharedWizToggleLabeledControl freebirdThemedCheckbox freebirdThemedCheckboxDarkerDisabled freebirdMaterialWidgetsToggleLabeledCheckbox isC ...

Is it necessary to install Chrome binaries on the Selenium grid in order to prevent receiving the error message "WebDriverError: unknown error: cannot locate Chrome binary"?

Recently, I have configured a new selenium grid on a Linux server using the following steps: The first command used was: 'java -jar ./selenium-server-standalone-3.141.59.jar -role hub' Then, the second command followed as: 'java -Dwebdrive ...

Start the Python script from a custom location specified by the user's input

Hey there fellow coders, I recently embarked on a project to create a chat bot using Python as a way to enhance my programming skills. However, I ran into a roadblock while trying to create a loop and was stumped on how to overcome it. Despite scouring the ...

Assistance with XPATH: Locating specific text and locating the subsequent button within a few divs down

New to XPATH... I'm attempting to locate specific text within a span element, followed by the next button in the code block below. The numbers associated with ember change dynamically, so I can't rely on those for identification. My goal is to lo ...

Capturing data-row value into a variable when the element is present

My current task involves extracting the data-row value into a variable if a specific element exists within a row. Here is my progress so far: if (drive.FindElement(By.XPath("//div[contains(., 'Automation')]")).Displayed) { // Code to extract ...

Ways to resolve issues with multiple foreign keys

Having trouble setting up multiple foreign keys and encountering errors from flask_sqlalchemy import SQLAlchemy sql= SQLAlchemy(app) app.secret_key = os.urandom(24) app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql:///test' ...

Tips for selecting a particular button using Python and Selenium

Struggling to locate and click on a specific button, I keep receiving the error message: "Message: Unable to locate element:" I have tried various options, but none of them seem to work: Option 1: driver.find_element_by_xpath('//button[contains(text ...

Is it possible to incorporate HTML tags within the <template> section of AIML files?

My goal is to create a simple bot using an AIML file. The idea is that I can input a question and the corresponding pattern will be returned from the file. For instance, I have this sample pattern in my AIML file: <category> <pattern>TEST& ...

Infobars in Chrome are spreading to other windows

As I dive deeper into this issue, please bear with me while I gather more information and update the question accordingly. I am currently working on automated tests using Selenium and Java within IntelliJ 2019. However, after upgrading Chrome to version 7 ...

What is the process for retrieving information from custom_export within Otree?

Currently, I am experimenting with utilizing ExtraModel and custom_export to extract information from the live_pages. However, after accessing the devserver and examining the data tab, I can't seem to locate the exported data. Furthermore, when I down ...

Discover the beauty of MultiSoup!

I am dealing with a list of items structured like this: (the number of items in the list may vary) <h3>My title</h3> <a href="http://myurl.com">http://myurl.com</a> <span class="t">text</span> <h3>My title</h3 ...

How to disable images in Firefox using Python's Selenium WebDriver

The code I used before is no longer working after the Firefox update. from selenium.webdriver.firefox.firefox_profile import FirefoxProfile firefoxProfile = FirefoxProfile() firefoxProfile.set_preference('permissions.default.image', 2) I have a ...

Analyzing array data with the use of for loops and conditional if statements

Here is the code snippet I am working with: import math import numpy import numpy as np import numpydoc import matplotlib x = [1, 2, 3, 4, 5, 6] y = [5, 6, 7, 8, 9, 10] ax = np.array(x) ay = np.array(y) for i in ax: if ax[i] > 4: print("H ...

Find out whether an M2M field contains a specifically designated through model

When working with a custom through model for an M2M relationship, the methods .add(), .create(), and .remove() are disabled. Currently, I am trying to utilize .add() (or something similar) but encountering and handling AttributeError exceptions due to the ...

Handling sporadic failures of Selenium tests during automated deployment

Our C#/ASP .Net web application undergoes the build and deployment process by our server, Jenkins. One crucial step in this process is ensuring that all automated tests, including functional tests using Selenium 2 WebDriver and NUnit, pass before deploymen ...

Ways to retrieve and store multiple values from a string

Currently, I'm analyzing the yelp dataset which contains a dictionary representing the schedule of various restaurants. The restaurant schedules are organized as follows: {'Friday': '8:0-23:0', 'Monday': '8:0-22:0& ...