使用 selenium python 将焦点移动到对象上 [英] Mouse the focus to an object using selenium python

查看:58
本文介绍了使用 selenium python 将焦点移动到对象上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Ubuntu Linux 上使用 selenium RC 和 python 2.7 自动化一个网站.这是我需要做的:

I am automating a website using selenium RC and python 2.7 on Ubuntu Linux. Here is what I need to do:

转到网站 http://borro.com.
使用 key down native 命令向下滚动到页面底部我需要将鼠标悬停在 g +1 上阅读工具提示
单击工具提示中显示的名称.

Go to the site http://borro.com.
Scroll down to the bottom of the page using key down native command I need to hover the mouse on g +1 read the tool tip
click on the name that appears in the tool tip.

我遇到的问题是——我需要将鼠标实际移动到那里,等待 2 秒,然后阅读工具提示并单击名称

The problem I am having is -- I need the mouse to physically move there, wait for say 2 secs and then read the tool tip and click on the name

鼠标没有在那里物理移动,我认为焦点丢失了,它说找不到元素 xpath.

The mouse is not physically moving there and I think the focus is lost and it says element xpath not found.

推荐答案

通过向元素发送一个空白键,使其获得焦点,我们已经解决了许多焦点问题.在这种情况下,您可能希望在工具提示出现后立即向其发送空白键.我熟悉 webdriver 但不熟悉 RC,但 RC 也应该有类似 send_key(element_xpath, " ") 的东西.

We've solved a lot of our focus issues by sending a blank key to the element so it gets focused. In this case, you'd probably want to send blank key to the tooltip as soon as it appears. I'm familiar with webdriver but not RC, but RC should have something like send_key(element_xpath, " ") as well.

要获取工具提示的 xpath,您可以使用 firebug,并在控制台中使用类似

To get the tooltip's xpath, you can use firebug, and in the console, use something like

$x("//*[contains(text(), 'Publicly recommend this as')]") 

确保找到此元素并且 xpath 正确.我还建议不要使用通配符,因此一旦找到工具提示的 xpath,请尝试将 * 替换为实际元素类型.

to make sure this element is found and xpath is correct. I also recommend not using wildcard characters, so once you find the tooltip's xpath, try to replace the * by the actual element type.

这篇关于使用 selenium python 将焦点移动到对象上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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