单击带有selenium2library的元素

时间:2013-01-29 08:47:27

标签: webdriver selenium-rc selenium-webdriver robotframework

我的整个测试套件基于带有SeleniumLibrary(RC)的机器人框架。我正在尝试将它移植到Selenium2(webdriver)。我遇到了点击元素关键字的问题,该关键字不再支持坐标参数。我读过this post,它提到了一个MoveToOffsetAction,但在从机器人框架看到的Selenium2Library中找不到它。 我还读到webdriver API有一个 click_at(locator,coordString)

总结一下情况,我想知道如何将我的selenium RC Click Element Locator Coordinates 转换为Selenium2关键字或一组关键字。

非常感谢你的帮助,

皮尔

1 个答案:

答案 0 :(得分:2)

在Selenium2 API中,没有选项可以使用坐标单击元素。

但您可以使用Action类来解决此问题。

试用此代码:

 //Assume driver is instantiated somewhere properly.
 WebElement ele = driver.findElement(By.xpath(Element locator));       
 Actions builder = new Actions(driver);
 builder.moveToElement(ele, 100, 200).click().perform();

通过使用上面的代码,您可以使用坐标(此处为按钮)移动到特定元素,并且可以单击。

了解更多信息http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/interactions/Actions.html