1

I'm trying to write a script to automate some tasks with Selenium and Python, and every time I try to click on a button

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options

driver = webdriver.Chrome(options=options)
xpath = "/html/body/app-root/app-prime/div/mat-sidenav-container//app-detail-component/main//div/span/button[@aria-label='Prenota']"

# Wait for the element to be visible, always true
WebDriverWait(driver, 5).until(expected_conditions.presence_of_element_located((By.XPATH, xpath)))
# Try to click on element, get an error
driver.find_element(By.XPATH, xpath).click()

I get the following error

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

I know for sure that the element gets located correctly and has to match, but it should act only on the first one.

I tried:

  • Trying to click child tags, such as others divs and span
  • Waiting for it to be clickable
  • Waiting with an implicit wait

None of those activities were successful

Edit: Apparently the issue olly exist on my machine

5
  • Did you deliberately removed the driver.get(url) line from your code? Commented Feb 23, 2022 at 14:54
  • Yep, the code does some operations before executing the code i posted so it was meaningless Commented Feb 23, 2022 at 15:36
  • Is it ok to share the website link here? Commented Feb 23, 2022 at 15:55
  • Actually i think it's not, it an academic site that requires login, but i can share part of the code website if it can help Commented Feb 23, 2022 at 16:12
  • Yes, please do so that the issue could be reproduced. Commented Feb 23, 2022 at 16:23

2 Answers 2

3

It could be not clickable for a number of reasons. You might want to check if there is some element on the page layered on top so that that element is not interactable at that time, e.g some popup/iframe etc. There could be some other element that will receive click at that time.

You could try an actions click - something like this

myElement = driver.find_element_by_xpath("myXpath")
webdriver.ActionChains(driver).move_to_element(myElement).click(myElement).perform()
Sign up to request clarification or add additional context in comments.

Comments

1

One of this should work.

IJavaScriptExecutor executor = (IJavaScriptExecutor)WebDriver.Driver;
            executor.ExecuteScript("arguments[0].click();", webElement);

Actions actions = new Actions(WebDriver.Driver);
            actions.MoveToElement(webElement).Click().Perform();

Note - these are c sharp code. try to do the same in java.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.