Unable to type within username field within ProtonMail signup page using Selenium and Python(无法使用 Selenium 和 Python 在 ProtonMail 注册页面的用户名字段中输入)
问题描述
您好,我正在尝试使用 Selenium 和 Python 为网站
我的代码如下:
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')执行以下代码后,出现错误:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="username"]"}(会话信息:chrome=83.0.4103.97)有什么建议吗?
Email Address 字段位于 中,因此您必须:
诱导 WebDriverWait 使所需的框架可用并切换到它.
诱导 WebDriverWait 使所需的元素可点击.
您可以使用以下任一
参考
您可以在以下位置找到相关讨论:
- iframe下#document的处理方式
- 通过 Selenium 和 python 切换到 iframe
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:
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?
解决方案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="UmVnaXN0cmF0aW9uIGZvcm0="]"))) 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="UmVnaXN0cmF0aW9uIGZvcm0="]"))) 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 ECBrowser Snapshot:
Reference
You can find a relevant discussion in:
- Ways to deal with #document under iframe
- Switch to an iframe through Selenium and python
这篇关于无法使用 Selenium 和 Python 在 ProtonMail 注册页面的用户名字段中输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法使用 Selenium 和 Python 在 ProtonMail 注册页面的
- 如何将一个类的函数分成多个文件? 2022-01-01
- 沿轴计算直方图 2022-01-01
- 分析异常:路径不存在:dbfs:/databricks/python/lib/python3.7/site-packages/sampleFolder/data; 2022-01-01
- pytorch 中的自适应池是如何工作的? 2022-07-12
- python-m http.server 443--使用SSL? 2022-01-01
- python check_output 失败,退出状态为 1,但 Popen 适用于相同的命令 2022-01-01
- 如何在 python3 中将 OrderedDict 转换为常规字典 2022-01-01
- 如何在 Python 的元组列表中对每个元组中的第一个值求和? 2022-01-01
- padding='same' 转换为 PyTorch padding=# 2022-01-01
- 使用Heroku上托管的Selenium登录Instagram时,找不到元素';用户名'; 2022-01-01
