Unable to perform Drag and Drop- Webdriver Java

I have tried to search a text in google images and then drag the element and drop. However it is not performing the same. When we manually move the mouse some action is occurring but drag and drop function is not performed.

WebDriver driver= new FirefoxDriver();
    driver.get("http://images.google.com/");
    Thread.sleep(1000);
    driver.findElement(By.name("q")).sendKeys("Apple");
    driver.findElement(By.name("btnG")).click();
    WebElement drag= driver.findElement(By.cssSelector("html body#gsr.srp div#main div#cnt.mdm div#rcnt div.col div#center_col div#res.med div#topstuff div#ifbc.prc div#ifb.prs a.rg_fbl div.rg_bb div.rg_bb_i div.rg_bb_layout div.rg_di img.rg_i"));
    WebElement drop= driver.findElement(By.cssSelector("html body#gsr.srp div#tphdr.tphdr div#mngb div#gb.gb_1b div.gb_Ab div.gb_k div#gbq div#gbq2.gbt div#gbqfw.gbqfr form#gbqf.gb_Nb fieldset#gbqff.gbqff div#gbfwa.gbqfwa div#gbqfqw.gbqfqw div#gbqfqwb.gbqfqwc table#gs_id0.gstl_0 tbody tr td#gs_tti0.gsib_a div#gs_lc0 input#gs_htif0.gbqfif"));
    Actions builder= new Actions(driver);
    Action dragelement= builder.clickAndHold(drag).build();
    dragelement.perform();
    Action dropelement=builder.moveToElement(drop).release(drop).build();
    dropelement.perform();

Answers


code to drag this element to an offset is

WebElement draggable = browser.findElement(By.id("draggable")); new Actions(browser).dragAndDropBy(draggable, 200, 10).build().perform();


Try This...

WebDriver driver = new FirefoxDriver();    
driver.get("http://images.google.com/");  

driver.switchTo().frame(0);   

driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);    

WebElement dragElement = driver.findElement(By.id("draggable"));  

WebElement dropElement = driver.findElement(By.id("droppable")); 

Actions builder = new Actions(driver);  // Configure the Action  

Action dragAndDrop = builder.clickAndHold(dragElement)
                            .moveToElement(dropElement)
                            .release(dropElement).build();  // Get the action  

dragAndDrop.perform(); // Execute the Action

Need Your Help

Can we create a wcf service for two protocols http and https

wcf wcf-data-services wcf-binding wcf-ria-services wcf-security

We need to create a WCF service which will be used by internal users using http and external users using https.

Speed up jQuery manipulation of a list

javascript jquery performance dom optimization

My application has a long list of objects whose width needs to be modified via jQuery. Currently I'm using code like this: