[英]Unable to click Username element with selenium python
I am trying to a write a bot that can make new ids of protonmail on demand我正在尝试编写一个可以按需生成新的质子邮件 ID 的机器人
link = https://account.proton.me/signup链接 = https://account.proton.me/signup
I am able to click and send keys to passwords and repeat password.我可以单击并发送密码密钥并重复密码。 But I am failing to click on the element of username.
但是我没有点击用户名的元素。 I am using selenium Python, my current code is:
我正在使用 selenium Python,我当前的代码是:
WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="email"]'))).click().send_keys(email)
But running into the following exception:但遇到以下异常:
selenium.common.exceptions.TimeoutException: Message:
Stacktrace:
#0 0x5594edc2d693 <unknown>
#1 0x5594eda26b0a <unknown>
#2 0x5594eda5f5f7 <unknown>
#3 0x5594eda5f7c1 <unknown>
#4 0x5594eda92804 <unknown>
#5 0x5594eda7c94d <unknown>
#6 0x5594eda904b0 <unknown>
#7 0x5594eda7c743 <unknown>
#8 0x5594eda52533 <unknown>
#9 0x5594eda53715 <unknown>
#10 0x5594edc7d7bd <unknown>
#11 0x5594edc80bf9 <unknown>
#12 0x5594edc62f2e <unknown>
#13 0x5594edc819b3 <unknown>
#14 0x5594edc56e4f <unknown>
#15 0x5594edca0ea8 <unknown>
#16 0x5594edca1052 <unknown>
#17 0x5594edcbb71f <unknown>
#18 0x7fe71dfa374d <unknown>
'//*[@id="email"]'
XPath locator while you need the second one.'//*[@id="email"]'
XPath 定位器匹配,而您需要第二个。WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe")))
username = WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="email"]')))
username.click()
username.send_keys(email)
When you finished working inside the iframe don't forget to switch to the default content with当您完成 iframe 内部的工作后,不要忘记使用以下命令切换到默认内容
driver.switch_to.default_content()
UPD UPD
edited according to @Tahirhan notes根据@Tahirhan 注释编辑
as @Prophet answered you should first switch to iframe and then interact with the element but click() method returns None and running send_keys() on None will give an error.正如@Prophet 回答的那样,您应该首先切换到iframe然后与元素交互,但click()方法返回None并且在None上运行send_keys()会出错。 Try this instead:
试试这个:
def sendEmail():
email = "testEmail"
WebDriverWait(browser, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe")))
el = WebDriverWait(browser,30).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="email"]')))
el.click()
el.send_keys(email)
browser.switch_to.default_content()
I write by another python module, it works, you need install chrome extension first by cc.chrome.extension.install_or_update()
我由另一个 python 模块编写,它可以工作,您需要先通过
cc.chrome.extension.install_or_update()
安装 chrome 扩展
from clicknium import clicknium as cc, locator, ui
#cc.chrome.extension.install_or_update()
tab = cc.chrome.attach_by_title_url(url="https://account.proton.me/signup")
tab.find_element_by_xpath('//*[@id="email"]').set_text("test")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.