如何点击对象所需的坐标?

时间:2017-03-27 16:11:44

标签: javascript jquery selenium google-chrome-extension

这是我在selenium中使用的代码。我使用chrome插件坐标找到了对象的坐标。它有一个ref框架作为页面的左上角。但是当我在下面的代码行中使用这些坐标时,点击就会发生在其他地方。在这种情况下,参考框架在哪里?如何点击准确的位置?

Actions uploadbtn = new Actions(BaseClass.driver);
     uploadbtn.moveToElement(Filter.FilterApplied(), 200, 0).click().build().perform();

1 个答案:

答案 0 :(得分:1)

  

“在这种情况下,参考框架在哪里?

假设Filter.FilterApplied()是WebElement,则引用框架是该元素的左上角。

  

“如何点击准确位置?

使用左上角是页面左上角的WebElement。

Actions actions = new Actions(BaseClass.driver); //You named this uploadbtn, but this doesn't really represent a button
actions.moveToElement(SomeEntirePageElement, 200, 0).click().build().perform();

或者更好的是,为什么不单击元素而不用担心坐标,因为按坐标点击可能会导致维护噩梦?

Filter.FilterApplied().click();
//Or are you trying to click an Upload button? If so, use a selctor for that button and click that.
相关问题