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.
- Element is not visible
- Element is present in off screen (After scroll down it will display)
- Element is present behind any other element
- 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.