Selenium/Python-悬停并单击元素 [英] Selenium/Python - hover and click on element

查看:95
本文介绍了Selenium/Python-悬停并单击元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Python上的Selenium脚本遇到问题.在我正在与之交互的javascript Web应用程序中,需要将其单击的元素才存在,直到将鼠标悬停在该元素上为止.我查看并找到了有关如何悬停的各种答案,但是序列需要包括在悬停事件期间单击新元素的过程.这是我目前正在使用的代码.一旦add1存在,当发生悬停时,该元素将从add重命名为add1;否则,元素将重命名为add1.我应该能够单击/发送键来执行所述元素.

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-悬停并单击元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆