Reputation: 229
Not sure what is the issue.. below code is supposed to work fine..
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class jusTrails {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "D:\\bala back up\\personel\\selenium\\Jars\\Drivers\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
driver.get("http://www.seleniumeasy.com/test/drag-and-drop-demo.html");
WebElement onlyOne=driver.findElement(By.xpath("//span[contains(text(), 'Draggable 1')]"));
System.out.println(onlyOne.getText());
WebElement dropHere1=driver.findElement(By.xpath("//*[@id='mydropzone']"));
Actions act=new Actions(driver);
act.dragAndDrop(onlyOne, dropHere1).build().perform(); //This should work fine.. BUT.
}
}
I am getting no exceptions but Draggable 1 wont move at all.. I tried this in another way but no luck..
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(onlyOne)
.moveToElement(dropHere1)
.release(dropHere1)
.build();
dragAndDrop.perform();
Upvotes: 1
Views: 187
Reputation: 181
This is apparently a known issue and there is a workaround. Granted it is in Ruby.
def drag_and_drop(source,target)
js_filepath=File.dirname(__FILE__)+"/drag_and_drop_helper.js"
js_file= File.new(js_filepath,"r")
java_script=""
while (line=js_file.gets)
java_script+=line
end
js_file.close
@driver.execute_script(java_script+"$('#{source}').simulateDragDrop({
dropTarget: '#{target}'});")
rescue Exception => e
puts "ERROR :" + e.to_s
end
Upvotes: 1