Selenium moveByOffset doesn't do anything

前端 未结 5 2009
轻奢々
轻奢々 2021-01-06 17:08

I\'m running latest selenium 2.41 with Firefox 28.0 on Linux Xubuntu 13.10

I\'m trying to get FirefoxDriver to move the mouse over the page (in my test, I\'ve used

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-06 17:18

    I struggled as well getting drag and drop working.

    It seems as if selenium has problems if the dragtarget is not visible, thus scrolling is requiered.

    Anyway, that's the (Java) code that works. Note that I call "release()" without an argument - neither the dropable Element nor the dragable Element as argument worked for me. As well as "moveToElement(dropable)" didnt work for me, that's why I calculated the offset manually.

    public void dragAndDrop(WebElement dragable, WebElement dropable,
            int dropableOffsetX, int dropableOffsetY) {
        Actions builder = new Actions(driver);
    
        int offsetX = dropable.getLocation().x + dropableOffsetX
                - dragable.getLocation().x;
        int offsetY = dropable.getLocation().y + dropableOffsetY
                - dragable.getLocation().y;
    
        builder.clickAndHold(dragable).moveByOffset(offsetX, offsetY).release()
                .perform();
    }
    

提交回复
热议问题