问题
So im trying to get my first ProtonMail Account Generator working. My Problem is that selenium wont find either the field for the recovery mail or the Create Account button. I switched to the iframe already. Im pretty new and thought that this problem might be caused by the "new" html document which contains the bottom part (starting with the recovery email). Hope someone can help me. Screenshot
from selenium import webdriver
import time
url = 'https://mail.protonmail.com/create/new?language=en'
driver = webdriver.Chrome('D:/Downloads/chromedriver')
driver.get(url)
time.sleep(2)
driver.switch_to.frame(driver.find_element_by_xpath("//iframe[@title='Registration form']"))
driver.find_element_by_id('username').send_keys('hallo')
time.sleep(1)
driver.switch_to.default_content()
driver.find_element_by_id('password').send_keys('password')
driver.find_element_by_id('passwordc').send_keys('password')
time.sleep(1)
driver.switch_to.frame(driver.find_element_by_xpath("//iframe[@title='Registration form']"))
driver.find_element_by_id('notificationEmail').send_keys('test')
driver.find_element_by_name('submitBtn').click()
回答1:
The Recovery email 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
XPATH
:WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//label[@for='notificationEmail']//following::div[@class='signupIframe-iframe']/iframe[@title='Registration form']"))) WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='notificationEmail']"))).send_keys("manu102")
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 couple of related discussions in:
- Unable to type within username field within ProtonMail signup page using Selenium and Python
- How to send text to the Password field within https://mail.protonmail.com registration page?
Outro
A couple of useful discussions:
- Ways to deal with #document under iframe
- Switch to an iframe through Selenium and python
来源:https://stackoverflow.com/questions/63420951/how-to-send-text-to-the-recovery-mail-field-of-https-mail-protonmail-com-creat