我正在尝试编写一个机器人,它可以按需生成protonmail的新ids
link = https://account.proton.me/signup
我可以点击和发送密钥到密码和重复密码。但是我没有点击用户名的元素。我正在使用selenium Python,我的当前代码是:
WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="email"]'))).click().send_keys(email)但是遇到以下异常:
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>发布于 2022-09-25 12:24:19
'//*[@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)当您完成在iframe中的工作时,不要忘记切换到默认的
driver.switch_to.default_content()UPD
按@Tahirhan注释编辑
发布于 2022-09-25 12:42:23
正如@Prophet回答的那样,您应该首先切换到iframe,然后与元素交互,但是click()方法返回None,在None上运行send_keys()将产生一个错误。试一试:
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()发布于 2022-09-25 13:51:40
我用另一个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")https://stackoverflow.com/questions/73844380
复制相似问题