Unable to type within username field within ProtonMail signup page using Selenium and Python

后端 未结 2 1306
借酒劲吻你
借酒劲吻你 2020-12-12 04:15

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

相关标签:
2条回答
  • 2020-12-12 05:04

    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.

    0 讨论(0)
  • 2020-12-12 05:13

    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:


    Reference

    You can find a relevant discussion in:

    • Ways to deal with #document under iframe
    • Switch to an iframe through Selenium and python
    0 讨论(0)
提交回复
热议问题