Does anyone has working example of drag and drop using JavascriptExecutor for WebDriver using Java?

726 views
Skip to first unread message

Gile

unread,
Sep 17, 2012, 5:25:38 PM9/17/12
to seleniu...@googlegroups.com
Something  happened in my app, drag and drop stopped working  in Chrome,  I am not sure if this is caused by  http://code.google.com/p/selenium/issues/detail?id=4455 (my app is usning GWT) or somethning changed on develeper's side (still waiting  on response - person who should know is on vacation :( ).
I need to get my tests working in Chrome again, cannot afford to wait any longer.

I am using version 2.25 for selenium and  chrome driver version 23.0.

code below works in Firefox but not in Chrome. I would like to try alternative approach and try drag and drop using  JavascriptExecutor. My  JavaScript knowledge is very limited, so I am asking for  help.
Help me please and  I will send happy thoughts to you (or buy you  a  drink if you are in Vancouver, Canada).

I found this example but it does not work: https://groups.google.com/forum/?fromgroups=#!searchin/webdriver/javascriptExecutor$20$20$20drag/webdriver/5xMxCrz4PxA/pG--kDJtuBgJ

Thanks in advance


WebElement source = driver.findElement(By.id("source"));
WebElement target = driver.findElement(By.id("target"));

//this works in Firefox but not in Chrome
(new Actions(driver)).dragAndDrop(source, target).perform();


//this also works in Firefox but not in Chrome
Actions builder = new Actions(driver);

 Action drag =
                builder
                           .moveToElement(source)
                           .clickAndHold(source)
                           .moveToElement(target)
                           .build();
        drag.perform();
       
       
Action release =
                builder
                         .clickAndHold(source)
                         .release(target)
                         .build();
 
 
 release.perform();       
Reply all
Reply to author
Forward
0 new messages