ElementClickInterceptedException Selenium unable to click button Python
I think that another element may be overlapped your element, and you should wait for the invisibility of this layer. The layer can be a loading frame or anything else.
WebDriverWait(driver, 20).until(EC.invisibility_of_element((By.CSS_SELECTOR, "selector_for_ovelapped_layer")))
and then click the element you needed
Also, you can use Actions:
element = driver.find_element_by_xpath("//input[@id='save' and @name='save'][@value='View Report']")
webdriver.ActionChains(driver).move_to_element(element).click(element).perform()
And you can do this with JSExecutor:
element = driver.find_element_by_xpath("//input[@id='save' and @name='save'][@value='View Report']")
driver.execute_script("arguments[0].click();", element)
ElementClickInterceptedException: Message: element click intercepted Element is not clickable error clicking a radio button using Selenium and Python
This error message...
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted:
Element <input type="radio" name="docTypes" ng-model="$ctrl.documentTypes.selected" id="documentType-0" ng-change="$ctrl.onChangeDocumentType()" ng-value="documentType" tabindex="0" class="ng-pristine ng-untouched ng-valid ng-empty" value="[object Object]" aria-invalid="false">
is not clickable at point (338, 202).
Other element would receive the click:
<label translate-attr="{title: 'fulfillment.documentAction.createNew.modal.documentType.document.title'}" translate-values="{documentName: documentType.name}" for="documentType-0" translate="ASN - DSD" tabindex="0" title="Select ASN - DSD document type">...</label>
...implies that the desired element wasn't clickable as some other element obscures it.
The desired element is a Angular element so to invoke click()
on the element you have 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, "label[for='documentType-0']"))).click()
Using
XPATH
:WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[@for='documentType-0']"))).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
Update
As an alternative you can use the execute_script()
method as follows:
Using
CSS_SELECTOR
:driver.execute_script("arguments[0].click();", WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "label[for='documentType-0']"))))
Using
XPATH
:driver.execute_script("arguments[0].click();", WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[@for='documentType-0']"))))
References
You can find a couple of relevant discussions in:
- Element MyElement is not clickable at point (x, y)… Other element would receive the click
- Selenium Web Driver & Java. Element is not clickable at point (x, y). Other element would receive the click
- ElementClickInterceptedException: Message: element click intercepted: Element is not clickable with Selenium and Python
ElementClickInterceptedException: Message: element click intercepted: Element label is not clickable with Selenium and Python
You need WebDriverWait
to make sure the element visibility_of_element_located
, then scroll to Searchable Database
section, and you can use locator by xpath
.
Please import :
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
Try the bellow code.
chromedriver_path = r"C:\Users\path\to\chromedriver.exe"
browser = webdriver.Chrome(executable_path=chromedriver_path)
url = "http://www.ncsl.org/research/transportation/autonomous-vehicles-legislative-database.aspx"
topics_xpath = "//div[@class='divTopicsSection1']//span//label[text()='All Topics']"
states_xpath = "//div[@class='divStatesSection1']//span//label[text()='All States']"
dBase_xpath = "//h4[text()='Searchable Database']"
browser.get(url)
WebDriverWait(browser, 10).until(expected_conditions.visibility_of_element_located((By.XPATH, topics_xpath)))
elem = browser.find_element_by_xpath(dBase_xpath)
browser.execute_script("arguments[0].scrollIntoView(true);", elem)
browser.find_element_by_xpath(topics_xpath).click()
browser.find_element_by_xpath(states_xpath).click()
ElementClickInterceptedException: Message: element click intercepted:
First of all try using element_to_be_clickable
instead of presence_of_element_located
.
If this still doesn't help you can use JavaClick
instead of driver.click()
.
So if this still will not work properly
for i in range(int(total_fill)):
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH,f'//*[@id="maincontentid"]/app-dashboard/app-itr-status/div[4]/div[{i+1}]/mat-card/div/div/div[4]/div[2]')))
b = driver.find_element_by_xpath(f'//*[@id="maincontentid"]/app-dashboard/app-itr-status/div[4]/div[{i+1}]/mat-card/div/div/div[4]/div[2]').click()
try this:
for i in range(int(total_fill)):
el = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH,f'//*[@id="maincontentid"]/app-dashboard/app-itr-status/div[4]/div[{i+1}]/mat-card/div/div/div[4]/div[2]')))
driver.execute_script("arguments[0].click();", el)
I have to notice: it is strongly not recommended to use such a complex locators like //*[@id="maincontentid"]/app-dashboard/app-itr-status/div[4]/div[{i+1}]/mat-card/div/div/div[4]/div[2]
they are extremely not reliably.
Also, please read here about the ElementClickInterceptedException
Selenium click next button yields selenium.common.exceptions.ElementClickInterceptedException
Here is a very simple running code snippet that uses XPATH to find the button Text "Se flere".
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("https://coop.no/sortiment/obs-bygg/hageuterom/hytter-boder-og-
drivhus")
element = driver.find_element_by_xpath('//button[text()="Se flere"]')
element.click()
Related Topics
Compare Object Instances for Equality by Their Attributes
How to Check If All Elements of a List Match a Condition
Numpy Array Is Not JSON Serializable
Finding Local Maxima/Minima with Numpy in a 1D Numpy Array
Plot Logarithmic Axes with Matplotlib in Python
How to Convert Each Item in the List to String, for the Purpose of Joining Them
Non-Alphanumeric List Order from Os.Listdir()
Using Lambda Expression to Connect Slots in Pyqt
Create Pandas Dataframe from Txt File with Specific Pattern
Python Analog of PHP's Natsort Function (Sort a List Using a "Natural Order" Algorithm)
How to State in Requirements.Txt a Direct Github Source
Using Python Requests with JavaScript Pages
Intuition and Idea Behind Reshaping 4D Array to 2D Array in Numpy
Getting "Permission Denied" When Running Pip as Root on My MAC
Should You Always Favor Xrange() Over Range()