Selenium/Python - hover and click on element(Selenium/Python - 悬停并单击元素)
问题描述
我在 Python 上的 Selenium 脚本遇到了问题.在我与之交互的 javascript Web 应用程序中,我需要单击的元素不存在,直到我将鼠标悬停在它上面.我已经查看并找到了有关如何悬停的各种答案,但序列需要包括在悬停事件期间单击新元素.这是我目前正在使用的代码.当出现悬停时,元素从 add 重命名为 add1,一旦 add1 存在;我应该可以单击/send.keys 来执行所述元素.
I'm running into an issue with my Selenium script on Python. In the javascript web application that I'm interacting with, an element I need to click doesn't exist until I hover over it. I've looked and found various answers on how to hover, but the sequence needs to include the clicking of a new element during the hover event. Here is the code I am currently working with. The element is renamed from add to add1 when a hover occurs, once add1 exists; I should be able to click/send.keys to execute said element.
...
driver = webdriver.Firefox()
from selenium.webdriver.common.action_chains import ActionChains
...
add = driver.find_element_by_css_selector('input.add')
Hover = ActionChains(driver).move_to_element(add)
Hover.perform()
SearchButton = driver.find_element_by_css_selector('input.add1')
SearchButton.click()
我是 Python 和一般编程的新手,但我不知道如何正确排序.
I'm new with Python and with programming in general, but I can't figure out how to sequence this correctly.
任何帮助将不胜感激.
推荐答案
以下对我有用,请试一试:
Following had worked for me, please give a try:
add = driver.find_element_by_css_selector('input.add')
SearchButton = driver.find_element_by_css_selector('input.add1')
Hover = ActionChains(driver).move_to_element(add).move_to_element(SearchButton)
Hover.click().build().perform()
我不确定上面的 Python 代码.但是你可以使用上面的逻辑.
I'm not sure about above Python code. But you can use above logic.
这篇关于Selenium/Python - 悬停并单击元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Selenium/Python - 悬停并单击元素
基础教程推荐
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 包装空间模型 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
