1

Hi I was trying to type the username field using Selenium and Python for the website https://mail.protonmail.com/create/new?language=en.

From the developer tool, I am able to inspect the item using CSSSelector/Xpath or other way. But when I am running the pthon script its not working. Screenshot attached:

enter image description here

My code is like the following:

BASE_URL = 'https://mail.protonmail.com/create/new?language=en'
driver = webdriver.Chrome(executable_path='./drivers/chromedriver')
driver.get(BASE_URL)
river.find_element_by_xpath('//*[@id="username"]').send_keys('someStringValue')

And after executing the following code, geetting the error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="username"]"}
  (Session info: chrome=83.0.4103.97)

Any suggestion?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Funny Boss
  • 328
  • 1
  • 3
  • 12
  • When you have text output, [don't take a picture but copy paste the output in your POST](https://unix.meta.stackexchange.com/questions/4086/psa-please-dont-post-images-of-text) The html can be copied as well from within the browser console: from inspector, right click -> copy as outerHTML. – Gilles Quénot Jun 13 '20 at 21:15

2 Answers2

1

The Email Address field is within an <iframe> so you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.

  • Induce WebDriverWait for the desired element to be clickable.

  • You can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

         driver.get('https://mail.protonmail.com/create/new?language=en')
         WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"div.usernameWrap iframe[title='Registration form']")))
         WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.input#username"))).send_keys("FunnyBoss")
    
  • Using XPATH:

         driver.get("https://mail.protonmail.com/create/new?language=en")
         WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//div[@class='usernameWrap']//iframe[@title='Registration form']")))
         WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='input' and @id='username']"))).send_keys("FunnyBoss")
    
  • 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_text


Reference

You can find a relevant discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Your xpath is OK, but the forms are inside an iframe.

So you need to switch to the iframe first:

driver.switchTo().frame(n);

Edit: If you read the TOS, you will see

This Service is provided exclusively to persons. Accounts registered by “bots” or automated methods are not authorized and will be terminated.

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223