Home > Enterprise >  Selenium, Element is not clickable at point while browser scrolls to this element
Selenium, Element is not clickable at point while browser scrolls to this element

Time:12-22

everyone.

I have code in python where I want to click at the element that is located near the end of page:

wait.until(visibility_of_element_located((By.CSS_SELECTOR, "input[name='do-import']")))
wait.until(element_to_be_clickable((By.CSS_SELECTOR, "input[name='do-import']")))

driver.find_element(By.CSS_SELECTOR, "input[name='do-import']").click()

I'm using ChromeDriver.

When launching this script, it scrolls to this element and then crashes with this message:

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (500, 1707)

I though maximizing window size will help, but it won't.

Why this is happening?

CodePudding user response:

You should first scroll till bottom with the below code:

driver.execute_script("var scrollingElement = (document.scrollingElement || document.body);scrollingElement.scrollTop = scrollingElement.scrollHeight;")

the try to click:

wait.until(element_to_be_clickable((By.CSS_SELECTOR, "input[name='do-import']"))).click()

But make sure that we have unique 1/1 entry in HTMLDOM:

input[name='do-import']

Steps to check:

Press F12 in Chrome -> go to element section -> do a CTRL F -> then paste the css selector and see, if your desired element is getting highlighted with 1/1 matching node.

or if that does not work, try with ActionChain:

Code trial 1:

driver.execute_script("var scrollingElement = (document.scrollingElement || document.body);scrollingElement.scrollTop = scrollingElement.scrollHeight;")
wait.until(element_to_be_clickable((By.CSS_SELECTOR, "input[name='do-import']"))).click()

Update:

As mentioned you need to basically scroll till end of the page to let Selenium have the web element in its viewport.

And then trigger Javascript command using execute_script like below:

driver.execute_script("var scrollingElement = (document.scrollingElement || document.body);scrollingElement.scrollTop = scrollingElement.scrollHeight;")
driver.execute_script("arguments[0].click();", wait.until(element_to_be_clickable((By.CSS_SELECTOR, "input[name='do-import']"))))
  • Related