python - 如何将文本发送到 https ://mail. protonmail.com 注册页面中的密码字段?

标签 python selenium selenium-webdriver iframe webdriverwait

我制作了质子注册表单,但没有输入密码

它在输入用户名时一切正常,但没有输入密码

正在输入用户名,但未输入密码。

代码试验:

''' python

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("start-maximized")
# chrome_options.add_argument('disable-infobars')
driver = webdriver.Chrome()
driver.get("https://protonmail.com/")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='btn btn-default btn-short' and @href='signup']"))).click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='row']//p[text()='Basic account with limited features']"))).click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn btn-primary btn-lg pull-right' and @id='freePlan']"))).click()
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("Hamza_Mirchi")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='password']"))).send_keys("Hamza_Mirchi")

'''

错误名称:

Traceback (most recent call last):
  File ".\proton-mail.py", line 16, in <module>
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='password']"))).send_keys("Hamza_Mirchi")
  File "C:\Users\Hamza Lachi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:

最佳答案

字符序列发送到密码字段作为 <iframe> 之外的所需元素所以你必须:

  • switch_to_default_content() .
  • 引发WebDriverWait以使所需的元素可点击
  • 您可以使用以下 Locator Strategies :

    • 代码块:

      chrome_options = webdriver.ChromeOptions() 
      chrome_options.add_argument("start-maximized")
      #chrome_options.add_argument('disable-infobars')
      driver = webdriver.Chrome(options=chrome_options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
      driver.get("https://protonmail.com/")
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='btn btn-default btn-short' and @href='signup']"))).click()
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='row']//p[text()='Basic account with limited features']"))).click()
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn btn-primary btn-lg pull-right' and @id='freePlan']"))).click()
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//div[@class='usernameWrap']//iframe[@title='Registration form']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='input' and @id='username']"))).send_keys("Hamza_Mirchi")
      driver.switch_to_default_content()
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='password']"))).send_keys("Hamza_Mirchi")
      
  • 浏览器快照:

protonmail_password

关于python - 如何将文本发送到 https ://mail. protonmail.com 注册页面中的密码字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57142447/

相关文章:

python - 如何使用变量作为标识符输入列表中的项目?

python - 长时间运行的 CPU 密集型 python 脚本被调度程序发送到 sleep 状态

java - 自动生成加特林场景

selenium - 机器人框架 : Reuse existing Browser Window between Tests

firefox - 无法单击存在但不可见的输入类型 ="button"

python - pip 要求说明符 : role of the comma

python - Conduit.simpleHttp - 执行带有 header 和数据的请求

java - 获取 org.testng.TestNGException : Cannot find class in classpath: error in eclipse during running my program through testng. xml

python - 使用 Python 和 Selenium 为什么我无法通过链接文本找到链接?

java - 如何处理 Selenium NoSuchElementException