2
from selenium import webdriver

browser = webdriver.Firefox() # Opens Firefox webbrowser
browser.get('https://protonmail.com/') # Go to www.protonmail.com website
loginButton = browser.find_element_by_css_selector('#bs-example-navbar-collapse-1 > ul > li:nth-child(8) > a') # Finds login button
loginButton.click()  # Clicks login button
browser.implicitly_wait(10) # wait until the site has fully loaded

usernameElem = browser.find_element_by_css_selector('#username') # Finds login element for email/username
usernameElem.send_keys('firstName.lastName@protonmail.com') # Enters email

passwordElem = browser.find_element_by_css_selector('#password') # Finds login element for password
passwordElem.send_keys('password') # Enters password # Enters password

This code crashes at the following line:

usernameElem.send_keys('firstName.lastName@protonmail.com')

The error message is:

selenium.common.exceptions.ElementNotInteractableException: Message: Element <input id="username" class="w100 inputform-field"> is not reachable by keyboard

I would like to understand, what the problem is first. I give the browser time to load. What is the reason for this error? And second: how can I solve the problem?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
aurumpurum
  • 932
  • 3
  • 11
  • 27
  • Does [this](https://stackoverflow.com/a/49872160/16136190) help? – The Amateur Coder Jan 21 '22 at 20:11
  • Thanks, but I am not familiar with JavaScript. Solutions using python are preferable. – aurumpurum Jan 21 '22 at 20:20
  • 1
    In that case, I think you can use [`WebDriverWait`](http://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/WebDriverWait.html) to wait until some conditions are satisfied, using [`ExpectedConditions`](http://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html). So, the code that combines both would look like: `WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.*(attr))).click()`. – The Amateur Coder Jan 21 '22 at 20:36

1 Answers1

2

The <input> field have a ancestor <label> as:

<label class="inputform-container w100 inputform-container--bigger" for="username">

Snapshot:

for_username


To send a character sequence to the element 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://protonmail.com/")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "li.action>a[href='https://mail.protonmail.com/login']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "label[for='username']"))).send_keys('firstName.lastName@protonmail.com')
    
  • Using XPATH:

    driver.get('https://protonmail.com/')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//li[@class='action']/a[@href='https://mail.protonmail.com/login']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[@for='username']"))).send_keys('firstName.lastName@protonmail.com')
    
  • 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:

protonmail_username


References

You can find a couple of relevant detailed discussions in:

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for your answer. I pasted the imports you suggested and your code using the CSS_SELECTOR strategy but I still get an "is not reachable by keyboard"-error at the line of code, where the user email should be putted in. I saw your screenshot...did you manage to get it exactly with that code you suggested? – aurumpurum Jan 22 '22 at 19:08
  • Yesterday the solution worked just perfecto with ChromeDriver/Chrome combo. – undetected Selenium Jan 22 '22 at 19:10
  • Ok, I am using Firefox...does it work also with this one with your code? – aurumpurum Jan 22 '22 at 19:11
  • The code is pretty generic and should work cross browser. – undetected Selenium Jan 22 '22 at 19:12
  • I have found the mistake: you must not attempt to invoke click() or sendKeys() on the – aurumpurum Jan 22 '22 at 19:20
  • Please don't get me wrong :) the other one is also my answer and I've provided the reference for your correspondence. The solution may vary as per the error you see. In this usecase, the solution I've proped is tested in Chrome. However I'm yet to check on Firefox. – undetected Selenium Jan 22 '22 at 19:23