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 - 悬停并单击元素


基础教程推荐
- 用于分类数据的跳跃记号标签 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 筛选NumPy数组 2022-01-01