python - 如何使用 Selenium 从右键菜单中选择选项
问题描述
我使用chrome作为驱动程序,双击/上下文单击后,提示窗口打开,但驱动程序不会切换到提示窗口。这是我尝试过的...我打开的页面是google.com,搜索,然后尝试右键单击,以便我可以在不同的选项卡中打开结果。提前致谢。
.......
element = driver.find_element_by_class_name("LC20lb")
actionchains = ActionChains(driver)
actionchains.context_click(element).perform()
# Driver needs to switch to the popup from here before it can press the down arrow.
sleep(5)
actionchains.send_keys(Keys.ARROW_DOWN).perform()
sleep(4)
driver.quit()
解决方案
使用 pyautogui,您可以在网页上下文之外按向下箭头。下面将选择 context minu 的第一个选项。尝试这个:
element = driver.find_element_by_class_name("LC20lb")
actionchains = ActionChains(driver)
actionchains.context_click(element).perform()
# Driver needs to switch to the popup from here before it can press the down arrow.
sleep(5)
#actionchains.send_keys(Keys.ARROW_DOWN).perform()
import pyautogui
pyautogui.press('down')
pyautogui.press('enter')
sleep(4)
driver.quit()
推荐阅读
- c# - 如何在Excel中打开在报表查看器中查看的报表而不先在VS2010 C#中保存
- git - Git Diff 和 Grep 输出字符串列表
- r - R:如何从日期中删除日期?
- angular - 如何使用单个服务人员安装多语言 Angular PWA?
- javascript - 为什么反应上下文提供程序组件呈现两次
- ms-access - 用于访问直通查询的雪花的 ODBC 连接字符串
- ios - 我可以检测用户是否点击了蓝色状态栏来打开应用程序?
- firebase - 在 Firestore 中按文档名称获取数据
- jekyll - 从 Jekyll 子文件夹中的 _posts 生成页面
- c# - 当构造线程同时进行写入和读取时,是否可以从另一个线程观察部分构造的对象?