Home > Back-end >  Selenium Element not interactable - python
Selenium Element not interactable - python

Time:06-29

I wrote a simple application in python, but when trying to click a button, I get an error Element not interactable. Here is a part of the code where it happens. I did wait for the element to render.

WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.XPATH, '//*[@id="root"]/div[2]/div/div/div[2]/ul/li/button')))
driver.find_element(By.XPATH, '//*[@id="root"]/div[2]/div/div/div[2]/ul/li/button').click()

The error happens on this website: https://magiceden.io/ when clicking Connect Wallet in the top right corner and then trying to click Phantom in the opening window.

CodePudding user response:

Reason behind this exception:

element not interactabe” exception may occur due to various reason.

  1. Element is not visible
  2. Element is present in off screen (After scroll down it will display)
  3. Element is present behind any other element
  4. Element is disable

For your case it's locator, you can use below locator to click on it.

XPATH

//header/nav[1]/div[2]/div[2]/div[1]/button[2]

OR

//button[contains(@xpath,'1')]

OR

(//button[contains(.,'Connect Wallet')])[1]

The Syntax should be like

element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "myXpath")))

element.click();

Imports

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

I have tested with First and third XPATH, it's working for me, let me know if this does not solve your issue.

  • Related