Selenium Webdriver将鼠标移动到Point [英] Selenium Webdriver move mouse to Point

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

问题描述

我目前正在尝试将光标移动到一个点( org.openqa.selenium.Point ),该点已通过检查是否出现标记而设置实时图表,我可以从中得到没有细节,但可以找到X和Y坐标。

I am currently trying to move the cursor to a point (org.openqa.selenium.Point) that has been set by checking for an occurrence of a marker on a live chart from which I can get no details but can find the X and Y coordinates of.

如何移动鼠标悬停在所述点以打开底层JavaScript菜单?

How can I move to the mouse to hover over said point to open the underlying JavaScript menu?

//finds marker on the current web page

Point image = page.findImage("C:\\Pictures\\marker.png") ;

//move mouse to this x,y location 

driver.getMouse().mouseMove((Coordinates) image);

这不起作用 Point 无法投出到 org.openqa.selenium.interactions.internal.Coordinates

This doesnt work as Point cannot be cast to org.openqa.selenium.interactions.internal.Coordinates.

推荐答案

恕我直言,你应该注意 Robot.class

IMHO you should pay your attention to Robot.class

如果你想在物理上移动鼠标指针,你需要采用不同的方法使用Robot类

  Point coordinates = driver.findElement(By.id("ctl00_portalmaster_txtUserName")).getLocation();
  Robot robot = new Robot();
  robot.mouseMove(coordinates.getX(),coordinates.getY()+120);

Webdriver提供文档坐标,其中Robot类基于屏幕坐标,所以我有添加+120以补偿浏览器标题。

屏幕坐标:这些是从用户计算机屏幕左上角开始测量的坐标。你很少得到坐标(0,0)因为它通常在浏览器窗口之外。关于您想要这些坐标的唯一时间是您要将新创建的浏览器窗口定位在用户单击的位置。
在所有浏览器中,这些都在 event.screenX event.screenY

窗口坐标:这些是从浏览器内容区域左上角开始测量的坐标。如果窗口垂直或水平滚动,则与文档的左上角不同。这很少是你想要的。
在所有浏览器中,这些都在event.clientX和event.clientY中。

文档坐标:这些是从HTML文档左上角开始测量的坐标。这些是您最常需要的坐标,因为这是定义文档的坐标系。

Webdriver provide document coordinates, where as Robot class is based on Screen coordinates, so I have added +120 to compensate the browser header.
Screen Coordinates: These are coordinates measured from the top left corner of the user's computer screen. You'd rarely get coordinates (0,0) because that is usually outside the browser window. About the only time you'd want these coordinates is if you want to position a newly created browser window at the point where the user clicked. In all browsers these are in event.screenX and event.screenY.
Window Coordinates: These are coordinates measured from the top left corner of the browser's content area. If the window is scrolled, vertically or horizontally, this will be different from the top left corner of the document. This is rarely what you want. In all browsers these are in event.clientX and event.clientY.
Document Coordinates: These are coordinates measured from the top left corner of the HTML Document. These are the coordinates that you most frequently want, since that is the coordinate system in which the document is defined.

您可以获得更多详细信息这里

More details you can get here

希望这对你有所帮助。

这篇关于Selenium Webdriver将鼠标移动到Point的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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