I want to input password to the box with Selenium but it returns selenium.common.exceptions.WebDriverException: Message: element not interactable
My python script:
from selenium import webdriver
browser = webdriver.Chrome(r'c:\chromedriver.exe')
url = 'https://creis.fang.com/'
browser.get(url)
browser.find_element_by_id('cnotp').send_keys('123456')
If I run the script, the above error appears. However, if I type line by line in the console. Then there is no error.
What should I do?
Thanks.
Maybe you should try to do it "by step". First select the element, clear its value then do the send_key stuff...
element = browser.find_element_by_id('cnotp')
element.clear()
element.send_keys('123456')
Hope it helps !
Wailt always whenever there is a url change.
from selenium import webdriver
driver = webdriver.Chrome() # Change
driver.get('https://creis.fang.com/')
element = WebDriverWait(driver, 60).until(
EC.presence_of_element_located((By.ID, "cnotp"))
)
element.clear()
element.send_keys("123456")
If it does not work, use js_executor
element = WebDriverWait(driver, 60).until(
EC.presence_of_element_located((By.ID, "cnotp"))
)
driver.execute_script("document.getElementById('cnotp').click()")
driver.execute_script("arguments[0].setAttribute('value', '123456')", element);
To send a character sequence within the password field using Selenium you have to induce WebDriverWait for the element_to_be_clickable()
and you can use either of the following solutions:
Using CSS_SELECTOR
:
driver.get("https://creis.fang.com/") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.loginipt.fl#cnotp"))).click() WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.loginipt.fl#cnpassword"))).send_keys("Chan")
Using XPATH
:
driver.get("https://creis.fang.com/") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='loginipt fl' and @id='cnotp']"))).click() WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='loginipt fl' and @id='cnpassword']"))).send_keys("Chan")
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
Browser Snapshot:
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.