首页 > 解决方案 > Python Selenium 不可能,试过 id,类找不到 XPath

问题描述

我正在尝试在用户名框中输入带有文本(电子邮件)的字段。但是,它没有与之交互。我在try&except声明中有它,但它只吐出异常。

网站是account.protonmail.com/signup

我已经尝试了一切:xpath, class, id,但没有任何效果。我快疯了!密码工作正常:

不工作:

driver.find_element_by_xpath('//*[@id="username"]').send_keys(password)

是否有效:

driver.find_element_by_xpath('//*[@id="repeat-password"]').send_keys(password) 

是的,我确实等到 JavaScript 完成运行。

标签: pythonselenium

解决方案


您尝试访问的元素位于 iframe 内。首先你需要像这样切换到框架

driver.switch_to.frame(driver.find_element_by_xpath("//iframe[contains(@src,'account-api.protonmail.com')]"))

推荐阅读