python-3.x - Selenium 无法在电子邮件模板中找到按钮
问题描述
我正在尝试使用 Selenium 在电子邮件模板中找到一个按钮并单击它,但无论我使用什么(xPath,css_selector),我的代码似乎都无法找到该按钮并不断收到此错误。
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element:
电子邮件在 Mailinator 中,我可以访问 Mailinator 和电子邮件正文,但是当click
操作即将执行时,我的代码无法抛出上述错误代码。
有没有人遇到过这个问题并且可以帮助我理解我做错了什么?如果您需要更多信息,请告诉我。非常感谢您的时间和帮助
解决方案
貌似是iframe,如果是,需要先切换,再交互:
代码 :
wait = WebDriverWait(driver, 10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "iframe xpath here")))
然后你可以互动:
wait.until(EC.element_to_be_clickable((By.XPATH, "email field xpath here"))).send_keys('pass some email address')
进口:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
完成后,切换到default content
这样的:
driver.switch_to.default_content()
推荐阅读
- python - 如何在python的csv输出中的每个表之前包含1个行空间并标记页码
- javascript - 使每个页面都变得更好的Javascript?
- flutter - 在页面上保持键盘打开并禁用每个关闭选项
- algorithm - 获取满足所有键的最少值
- laravel - Laravel 中的自定义多态类型
- java - 如何在鼠标移动创建的矩形上使用工具提示 - Java
- python - 运行假设时如何退出 pdb 调试?
- c# - 当同时撰写多封电子邮件时,Outlook 不会触发 AttachmentAdd 事件,但一封电子邮件除外
- json - 如何在 json 文件中使用变量?
- react-native - React Native webview with login facebook总是在发布模式下重定向到另一个url(仅限android)