Selenium 将鼠标光标移动到元素在 Firefox 中不起作用 [英] Selenium move mouse cursor to element not work in Firefox

查看:19
本文介绍了Selenium 将鼠标光标移动到元素在 Firefox 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

=================================

================================

操作系统:Win7

硒:2.33.0

火狐:22.0

Python:2.7.4

Python: 2.7.4

=================================

================================

我想用move_to_element"方法将鼠标光标移动到input"元素,但做不到.

I want to move the mouse cursor to the element "input" with method "move_to_element", but can't do it.

有人有这个问题吗?

=================================

================================

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from selenium.webdriver.common.by import By

import selenium.webdriver as webdriver
import time


firefox = webdriver.Firefox()

firefox.get("http://www.baidu.com")


input = firefox.find_element_by_id("kw")

action = webdriver.ActionChains(firefox)
action.send_keys_to_element(input, "testvalue")
action.perform()

#This step (move mouse to "input" element) NOT work! :(
action = webdriver.ActionChains(firefox)
action.move_to_element(input)
action.perform()


time.sleep(3)
firefox.quit()

问题解决了.我认为 move_to_element() 方法应该将真正的鼠标光标移动到对象上.但是 selenium 鼠标悬停而不移动真正的鼠标光标.谢谢.

Problem solved. I thought move_to_element() method should move the real mouse cursor to the object. But selenium does the mouse hover without moving real mouse cursor. Thanks.

推荐答案

试过你的代码.你的意思是行不通?你预计会发生什么?

Tried your code. What you do mean doesn't work? What do you expect to happen?

鼠标悬停在百度输入端时没有视觉效果.Selenium 在不移动真实鼠标的情况下移动到元素,因此您不会看到真实鼠标光标的位置变化.

There is no visual effect when you hover to Baidu's input. Selenium moves to the element without moving the real mouse, so you won't see the position change of the real mouse cursor.

如果你真的想测试move_to_element,请针对具有悬停效果的东西进行测试,这样你就可以直观地看到它.

If you really want to test move_to_element, please test against something that has hover effect, so you can visually see it.

这是一个例子:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from selenium.webdriver.common.by import By

import selenium.webdriver as webdriver
import time


firefox = webdriver.Firefox()

firefox.get("http://stackoverflow.com/tags")


tags = firefox.find_elements_by_css_selector("#tags-browser .tag-cell .post-tag")

action = webdriver.ActionChains(firefox)
action.move_to_element(tags[0])
action.perform()

这篇关于Selenium 将鼠标光标移动到元素在 Firefox 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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