Trying to update my code to use "driver.find_element(By.XPATH..." instead of "driver.find_elements_by_xpath(...", but I keep getting the following the error when I send keys:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
Here is my code:
driver = webdriver.Chrome(PATH)
link_login = "https://www.wyzant.com/tutor/jobs"
driver.get(link_login)
username_input = driver.find_element(By.XPATH, "//*[@id='Username']")[1]
username_input.send_keys("Test")
CodePudding user response:
To send a character sequence within the Username field you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:
Using CSS_SELECTOR:
driver.get("https://www.wyzant.com/tutor/jobs") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "form.sso-login-form input#Username"))).send_keys("rushi")Using XPATH:
driver.get("https://www.wyzant.com/tutor/jobs") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//form[@class='sso-login-form']//input[@id='Username']"))).send_keys("rushi")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
CodePudding user response:
- Try using more precise XPath locator.
- The entire XPath expression should be inside the
(By.XPATH, "your_xpath_expression") - You should also use expected conditions explicit waits
This should work:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//form[@action='/sso/login']//input[@id='Username']"))).send_keys(your_user_name)
You will need to import these imports:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
CodePudding user response:
Use find_elements instead of find_element to select the element like you do in your example:
driver.get('https://www.wyzant.com/tutor/jobs')
username_input = driver.find_elements(By.XPATH, "//*[@id='Username']")[1]
username_input.send_keys("Test")
or change your xpath to select more specific '//form[@]//*[@id="Username"]':
driver.get('https://www.wyzant.com/tutor/jobs')
username_input = driver.find_element(By.XPATH, '//form[@]//*[@id="Username"]')
username_input.send_keys("Test")
