selenium.common.exceptions.ElementClickIntercepted
Exception: Message: element click intercepted error clicking a radio-button using Selenium Python
This error message...
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <label class="mob-mar-b-dbl font-18-important ng-binding" for="no-renovate">...</label> is not clickable at point (1148, 360). Other element would receive the click: <div id="loader" ng-show="loading" class="loader-overlay" tabindex="-1" aria-labelledby="loading-msg" role="alert" aria-live="assertive" style="">...</div>
...implies that the click event on the <label>
element is being intercepted by a loader-overlay.
To click() on the <label>
element:
First you have to induce WebDriverWait for the invisibility_of_element_located() for the loader element.
Then induce WebDriverWait for the desired element_to_be_clickable() and you can use either of the following locator strategies:
CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.invisibility_of_element_located((By.CSS_SELECTOR, "div.loader-overlay#loader[ng-show='loading'][aria-labelledby='loading-msg']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "label[for='no-renovate']"))).click()XPATH:
WebDriverWait(driver, 20).until(EC.invisibility_of_element_located((By.XPATH, "//div[@class='loader-overlay' and @id='loader'][@ng-show='loading' and @aria-labelledby='loading-msg']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[@for='no-renovate']"))).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.common.exceptions.ElementClickIntercepted
Exception: Message: element click intercepted: Element is not clickable with Selenium and Python
If the path of the xpath is right, maybe you can try this method to solve this problem. Replace the old code with the following code:
button = driver.find_element_by_xpath("xpath")
driver.execute_script("arguments[0].click();", button)
I solved this problem before, but to be honestly, I don't know the reason.
Problem with selenium.common.exceptions.ElementClickIntercepted
Exception: Message: element click intercepted:
Instead of
wait.until(EC.element_to_be_clickable(lead.click()))
Try using
wait.until(EC.visibility_of(lead))
time.sleep(0.5)
driver.execute_script("arguments[0].click();", lead)
UPD
To close the grayed screen in order to click on the next lead
element try clicking on some element with actions.
actions = ActionChains(browser)
title = browser.find_element_by_xpath('//title[contains(text(),"LinkedIn")]')
actions.move_to_element(title).click().perform()
The entire code block will be something like this:
actions = ActionChains(browser)
title = browser.find_element_by_xpath('//title[contains(text(),"LinkedIn")]')
lead_links = []
leads_button = browser.find_elements_by_class_name('button--unstyled.t-16.font-weight-600.nowrap-ellipsis')
for lead in leads_button:
wait = WebDriverWait(browser, 10)
wait.until(EC.visibility_of(lead))
time.sleep(0.5)
driver.execute_script("arguments[0].click();", lead)
leads = soup.find_all("div", attrs={
'class': 'artdeco-entity-lockup__title.artdeco-entity-lockup__title--alt-link.ember-view'})
for lead_person in leads:
lead_links.append(lead_person.a["href"])
actions.move_to_element(title).click().perform()
Python & Selenium: ElementClickIntercepted
Exception: Message: element click intercepted error
Try:
pos = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//*[text()="positionlist"]')))
pos.click()
OR
pos = WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, '//*[@id="order-bar"]/div/button')))
pos[1].click()
OR js execute and click()
pos = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="pos-list"]')))
driver.execute_script("arguments[0].click();", pos)
Selenium - element click intercepted: Element is not clickable at point
That page can be scraped without the overheads and complexities of Selenium: you can use requests/bs4 instead:
import requests
from bs4 import BeautifulSoup
headers= {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'}
s = requests.Session()
s.headers.update(headers)
for x in range(1, 10): ## pick up the range here
r = s.get(f'https://g1.globo.com/ciencia/index/feed/pagina-{x}.ghtml', headers=headers)
soup = BeautifulSoup(r.text, 'html.parser')
news = soup.select('div.feed-post-body')
for n in news:
title = n.select_one('a')
print(title.get_text(strip=True))
This returns the titles, but you can select any other elements:
O supertelescópio que vai investigar a origem das estrelas
Pesquisa liga beijos na Idade do Bronze a origem da herpes labial
Os animais que fazem arte - e podem ter vantagens evolutivas com isso
O que é a hipótese de Gaia, que defende que a Terra 'está viva'
Septuagenárias e rebeldes
If you are keen on using Selenium, then bear in mind that page will load the first three pages worth of news by detecting scrolling to the bottom of the page, and then you can click the button to take you to page 4. You also need to dismiss the cookie button, and to wait for the heavy javascript adverts from page to load.You also need to account for the actual url of the page changing on click, and to redefine the elements.
selenium.common.exceptions.ElementClickIntercepted
Exception: Message: element click intercepted: Element is not clickable at point
You can perform JavaScriptExecutor
click on the element as it directly performs the action on the div and is not affected by the position of the element on the page or the headless option.
You can do it like:
button = driver.find_element_by_xpath("_tmp_")
driver.execute_script("arguments[0].click();", button)
Related Topics
Python Unicode Equal Comparison Failed
Using Lxml and Iterparse() to Parse a Big (+- 1Gb) Xml File
Appending Item to Lists Within a List Comprehension
Why Are Python Strings and Tuples Are Made Immutable
How to Iterate Through Dictionary in a Dictionary in Django Template
Handling Multiple Requests in Flask
Image Segmentation Based on Edge Pixel Map
Matplotlib Yaxis Range Display Using Absolute Values Rather Than Offset Values
Comparing Numpy Arrays Containing Nan
Replace First Occurrence of String in Python
How to Use a Conditional Expression (Expression with If and Else) in a List Comprehension
How to Use Python to Get the System Hostname
How to Call an External Program in Python and Retrieve the Output and Return Code