Clicking at coordinates without identifying element

前端 未结 14 1902
醉酒成梦
醉酒成梦 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:06

    This can be done using Actions class in java

    Use following code -

    new Actions(driver).moveByOffset(x coordinate, y coordinate).click().build().perform(); 
    

    Note: Selenium 3 doesn't support Actions class for geckodriver

    Also, note that x and y co-ordinates are relative values from current mouse position. Assuming mouse co-ordinates are at (0,0) to start with, if you want to use absolute values, you can perform the below action immediately after you clicked on it using the above code.

    new Actions(driver).moveByOffset(-x coordinate, -y coordinate).perform();

提交回复
热议问题