0

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")
HedgeHog
  • 22,146
  • 4
  • 14
  • 36
rushi
  • 225
  • 1
  • 3
  • 7

3 Answers3

5

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[@class="sso-login-form"]//*[@id="Username"]':

driver.get('https://www.wyzant.com/tutor/jobs')
username_input = driver.find_element(By.XPATH, '//form[@class="sso-login-form"]//*[@id="Username"]')
username_input.send_keys("Test")
HedgeHog
  • 22,146
  • 4
  • 14
  • 36
3
  1. Try using more precise XPath locator.
  2. The entire XPath expression should be inside the (By.XPATH, "your_xpath_expression")
  3. 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
Prophet
  • 32,350
  • 22
  • 54
  • 79
0

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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352