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

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

问题描述

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

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

操作系统:Win7的

硒:2.33.0

火狐:22.0

的Python:2.7.4

Python: 2.7.4

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

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

我想鼠标光标移到元素输入与法move_to_element,但不能做到这一点。

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()方法应该真正的鼠标光标移动到该对象。但硒确实鼠标悬停不动,真正的鼠标光标。谢谢。

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.

推荐答案

想你的code。你做什么的意思是不工作?你有什么期望发生?

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

有没有视觉效果,当鼠标悬停到百度的输入。硒移动的元素,而无需移动鼠标真正的,所以你不会看到真正的鼠标光标的位置变化。

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()

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

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