简体   繁体   中英

Selenium Element not interactable - python

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM