SELENIUM PYTHON ElementClickInterceptedException: - python

I'm writing a Selenium Python script. Unfortunately, I can't click "Sign in" button or check mark.
I've tried many ways. I'll be glad if anyone helps me plz.
Link:
https://stagingskateontario.memberlounge.ca/auth/login
My Code:
wait.until(EC.element_to_be_clickable((By.ID, ":r2:")))
driver.find_element(By.ID,":r2:").click()
Error:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (790, 723)
(Session info: chrome=103.0.5060.134)
enter image description here

I was able to click the button with javascript
element = browser.find_element_by_xpath("/html/body/div/main/div/div/div[2]/form/button")
browser.execute_script("arguments[0].click();", element)

JavaScriptExecutor is an Interface that helps to execute JavaScript through Selenium Webdriver. JavaScriptExecutor provides two methods “executescript” & “executeAsyncScript” to run javascript on the selected window or current page.

Related

Find button with Selenium on python

I'm trying to retrieve data from this button but it raises the following error: selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable.
Button source code:
<button class="Blockreact__Block-sc-1xf18x6-0 Buttonreact__StyledButton-sc-glfma3-0 bqHBns jFqMrE ActionButtonreact__StyledButton-sc-7jpoey-0" type="button"><div class="Blockreact__Block-sc-1xf18x6-0 Flexreact__Flex-sc-1twd32i-0 olSpy jYqxGr"><i value="add" size="24" class="Iconreact__Icon-sc-1gugx8q-0 irnoQt material-icons">add</i></div></button>
My code:
browser.find_element_by_xpath("//button[#type='button']")
Page: Add item on https://opensea.io/asset/create
Since the browser maximize isn't working for you.
Did you try with ActionsChains ?
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).move_to_element(browser.find_element_by_xpath("//i[#value='add']/../..")).click().perform()
Click the button not the icon. xpath:
.//body/div[1]/div[1]/main/div/div/section/div[2]/form/section[6]/div[1]/div/div[2]/button
You can also use element waits package to ensure the button is interactable first
wait.until(ExpectedConditions.visibilityOfElementLocated(by));
wait.until(ExpectedConditions.elementToBeClickable(by));
Then click

python selenium: element click intercepted:

I'm trying to click via find_element_by_xpath() as i did it always. In the case below, there is an error when try to click this element. I'm quite new with selenium and researched already. It seems that i have to click on specific coordination. Do you have any idea how to solve this problem? i'm struggling for quite a while.
section of HTML code:
<map ng-if="!enableSvgHighlighting" id="clickareasVillage" name="clickareasVillage"
ng-show="areas.village.length > 0" class="">
<area ng-repeat="a in areas.village" location-id="32" on-pointer-over="highlightStart(32)" on-
pointer-out="highlightStop(32)" clickable="openBuildingDialog(32)" tg-
coords="758,341,758,342,761,343,763,344,767,345,769"
coords="758,341,758,342,761,343,763,344,767,345,769"
shape="poly" building-positioner="32" class="clickable">
my Code:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//map[#id='clickareasVillage']/area[2]")))
ele1=driver.find_element_by_xpath("//map[#id='clickareasVillage']/area[2]")
ele1.click()
error message:
ElementClickInterceptedException: element click intercepted: Element
<area ng-repeat="a in areas.village" location-id="32"
on-pointer-over="highlightStart(32)" on-pointer-out="highlightStop(32)" clickable="openBuildingDialog(32)"
tg-coords="758,341,758,342,761,343,763,344,767,345,769" coords="758,341,758,342,761,343,763,344,767,345,769"
shape="poly" building-positioner="32"
class="clickable"> is not clickable at point (391, 477).
Other element would receive the click: <img ng-if="!enableSvgHighlighting"
ng-show="areas.village.length > 0" class="clickareas" src="layout/images/x.gif" usemap="#clickareasVillage" data-cmp-info="9">
on other treads at stackoverflow, people suggest to use the following line. If i try, there is a TimeoutExeption.
WebDriverWait(driver, 20).until(EC.invisibility_of_element((By.XPATH, "//map[#id='clickareasVillage']/area[2]")))
As said above, usually when you encounter this error it's because a pop-up or an invisible overlay is preventing the driver from clicking on your element.
You said that JS clicking wasn't working either so i'm going to give you 2 quick workarounds that you can try:
ActionChains to move and click on your element:
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).move_to_element(element).click().perform()
Send keys using ActionChains
from selenium.webdriver.common.action_chains import ActionChains
for i in range(#determine how much time):
ActionChains(driver).send_keys(Keys.TAB).perform() #tab until element is selected
ActionChains(driver).send_keys(Keys.ENTER).perform() #press enter to "click" on it
Let me know if that helped you.
Try using javascript
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//map[#id='clickareasVillage']/area[2]")))
driver.execute_script("arguments[0].click();", element)
There may be something which could be preventing click on the element, check if any pop-up occuring.

Unable to locate element in Python Selenium webdriver find_element_by_xpath

i'm trying to click the "download Results" button on this website .
i'm using below python code to click this button
from selenium import webdriver
chromedriver_path = 'E:/software/python/chromedriver'
url = 'https://www.cms.gov/apps/physician-fee-schedule/search/search-results.aspx?Y=0&T=4&HT=2&CT=3&H1=74750&H2=74800&M=5'
driver= webdriver.Chrome(executable_path=chromedriver_path )
driver.get(url)
driver.find_element_by_xpath('//*[#title="Download Results"]').click()
i'm getting below error
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//frame[#name="aspnetForm"]"}
(Session info: headless chrome=83.0.4103.116)
i'm thinking if the button is within a iframe but how do I find out the iframe?
This may help you out: Unable to locate element using selenium webdriver in python
Try and switch to the frame first, and then search for the element.
i realized that there's a agreement page that i need to click 'Agree' button first.
i didn't see this in browser because i already clicked 'Agree' weeks ago. but in webdriver, i need to click that each time.
Just after the URL opens, a page comes up asking you to agree the terms. You need to click on that Agree first. Since it is possible that once clicking on the Agree button, it won't come again if you accepted it on default browser. So just be sure with code, you can first check the presence of the agree button first.
This kind of function you may make to check presence:
def elementPresent(locatorType, locator):
#present = true
#not present = false
wait = WebDriverWait(driver, 20)
try:
wait.until(EC.presence_of_element_located((locatorType, locator)))
except Exception:
return False
return True
And then using if condition you may proceed further like:
if(elementPresent("xpath", "//a[#title='Accept']/span")):
driver.find_element_by_xpath("//a[#title='Accept']/span").click()
and then you may click on the element you want, there is no frame that is required to be switched to.
driver.find_element_by_xpath("//a[#title = 'Download Results']/span").click()
Just extract the element and click on it and your required file will be downloaded.

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable with Selenium and Python

I am currently working on a project which fills a form automatically. And the next button appears when the form is filled, that's why it gives me an error.
I have tried:
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,"//input[#type='button' and #class='button']")))
Next = driver.find_element_by_xpath("//input[#type='button' and #class='button']")
Next.click()
HTML:
<span class="btn">
<input type="button" value="Next" class="button" payoneer="Button" data-controltovalidate="PersonalDetails" data-onfieldsvalidation="ToggleNextButton" data-onclick="UpdateServerWithCurrentSection();" id="PersonalDetailsButton">
</input>
<div class="clearfix"></div>
</span>
ERROR:
selenium.common.exceptions.ElementClickInterceptedException: Message:
element click intercepted: Element is not clickable at point (203, 530).
Other element would receive the click: ... (Session info: chrome=76.0.3809.132)
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.
This error message...
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (203, 530). Other element would receive the click: ... (Session info: chrome=76.0.3809.132)
...implies that the click() on the desired element was intercepted by some other element and the desired element wasn't clickable.
There are a couple of things which you need to consider as follows:
While using Selenium for automation using time.sleep(secs) without any specific condition to achieve defeats the purpose of automation and should be avoided at any cost. As per the documentation:
time.sleep(secs) suspends the execution of the current thread for the given number of seconds. The argument may be a floating point number to indicate a more precise sleep time. The actual suspension time may be less than that requested because any caught signal will terminate the sleep() following execution of that signal’s catching routine. Also, the suspension time may be longer than requested by an arbitrary amount because of the scheduling of other activity in the system.
You can find a detailed discussion in How to sleep webdriver in python for milliseconds
As WebDriverWait returns the WebElement you can invoke the click() method directly.
Solution
To click on the button with value as Next you can use either of the following Locator Strategies:
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.button#PersonalDetailsButton[data-controltovalidate='PersonalDetails']"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#class='button' and #id='PersonalDetailsButton'][#data-controltovalidate='PersonalDetails']"))).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
i faced similar issues, the .click() always returns a Not clickable exception. the
driver.execute_script('arguments[0].click()', button)
does the magic. You can also use it to execute any other js script this way
script = 'your JavaScript goes here'
element = driver.find_element_by_*('your element identifier goes here')
driver.execute_script(script, element)
I looked at the exact element that was causing it and it was a banner about consent/cookies. So at first, I made sure it clicked "OK" on the consent banner and then I clicked the other button that I needed. Hope it helps someone.
It look's like there are some other elements which are having the same xpath try changing the xpath something like this
Next = driver.find_element_by_xpath("//input[#id='PersonalDetailsButton']");
Next.Click();
or
Next = driver.find_element_by_xpath(//input[#value='Next' and #id='PersonalDetailsButton']);
Next.Click();
Try first xpath if that doesn't work go with the second one . If that also doesn't work try using sikuli. I am pretty sure that first xpath will work
I faced a similar issue and I observed something that might help to understand the root cause of the issue. In my case, I was able to click at an element being in PC view mode of the website but failed to do so in mobile view (in which I needed my script to run). I found out that in mobile view, ordering of elements (li in my case) changed in view while they remained same in the html document. That's why I was not able to click on it without actually scrolling to it first. It might also explain why this works: -
driver.execute_script("arguments[0].click();", button)
I don't have enough rep to comment but the common reason for this error might be Selenium locates the element from DOM on screen and locate the x-y coordinates (300, 650) then clicks on them but if some changes takes place on screen in between the click duration, for example google ads or some pop-up then it's unable to click on it resulting in this exception
I'm just guessing if anyone has a proper explanation to pls share
I had the same problem too. But my problem was not with the element. The button was activated with href. I changed the code from
<a class="services-button" href="desired url">
To
<a class="services-button" onclick="location.href='{% url "desired url" %}'";">
This solution worked for me :
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Firefox(executable_path="")
driver.get("https://UrlToOpen")
action = ActionChains(driver)
firstLevelMenu = driver.find_element_by_id("menu")
firstLevelMenu.click()
source : http://allselenium.info/mouse-over-actions-using-python-selenium-webdriver/
"selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable ... "
This exception occurs when element is not found on a web page (When the element we are looking for is at bottom part of the page which is not loaded yet)
So we you can scroll the page using javascript and load complete page and
from selenium.webdriver.common.by import By
from selenium import webdriver
url = "YOUR URL"
SCROLL_PAUSE_TIME = 0.5
driver = webdriver.Chrome()
driver.maximize_window()
driver.get(url)
def scroll_page():
i = 0
while i < 5:
# Scroll down to 500 pixel
driver.execute_script("window.scrollBy(0, 500)", "")
# Wait to load page
time.sleep(SCROLL_PAUSE_TIME)
# Will scroll only for 4 increments of 500px
i += 1
You could try:
driver.execute_script("arguments[0].click();", button)
This solution solved my problems when I faced similar issues.

Selenium generating error "Element is not interactable"

I am trying to use Selenium to click the button highlighted above. I have no problem locating the element via:
download_button_path = "//button[#class='btn-primary']"
download_button = driver.find_element_by_xpath(download_button_path)
However when I try and execute:
download_button.click()
I get the error message:
ElementNotVisibleException: Message: element not interactable
(Session info: chrome=70.0.3538.67)
(Driver info: chromedriver=2.42.591059 (a3d9684d10d61aa0c45f6723b327283be1ebaad8),platform=Mac OS X 10.11.6 x86_64)
It seems the button is not visible to selenium even though I am able to see it when performing the click manually.
I have also tried to hover over the button and then click, as well as send an Enter/Return key to the button, but nothing is working.
Any insight would be appreciated.
In the HTML, I see the btn-primary is present in a bootstrap modal popup. So there may another btn-primary behind the modal pop. The XPath will be finding the element which is behind the modal which is not interactable.
btn-primary class is a generic class in bootstrap that will be used in all primary buttons. Try with unique locator with reference to modal element as a parent in your locator
download_button_path = "//[#class='lmn-edititem-modal']/../[#class=''btn-primary']"
wait = WebDriverWait(driver, 10)
download_button = wait.until(EC.visibility_of_element_located((By.XPATH, download_button_path)))
download_button .click()
We can also try this with CSS selector
driver.find_elements_by_css_selector(".lmn-edititem-modal .btn-primary")
For me, extending relative Xpath just with its parent helped.
button = driver.find_element_by_xpath("//button[#data-value='0']")
button.click()
#this did not work
button = driver.find_element_by_xpath("//section[2]/button[#data-value='0']")
button.click()
#this worked well
Have you tried hovering over the button and then clicking?
try the following:
button_to_click = driver.find_element_by_xpath('button_to_click's xpath')
hover = ActionChains(driver).move_to_element(button_to_click)
hover.perform()
button_to_click.click()
Hope this helps.

Categories

Resources