Clicking at coordinates without identifying element

前端 未结 14 1924
醉酒成梦
醉酒成梦 2020-11-28 07:49

As part of my Selenium test for a login function, I would like to click a button by identifying its coordinates and instructing Selenium to click at those coordinates. This

14条回答
  •  无人及你
    2020-11-28 08:02

    This worked for me in Java for clicking on coordinates irrespective on any elements.

    Actions actions = new Actions(driver);
    actions.moveToElement(driver.findElement(By.tagName("body")), 0, 0);
    actions.moveByOffset(xCoordinate, yCoordinate).click().build().perform();
    

    Second line of code will reset your cursor to the top left corner of the browser view and last line will click on the x,y coordinates provided as parameter.

提交回复
热议问题