0

Both functions works great on its own. But when I put them together. After I drag and drop the first element, I can't drag and drop the same element in the empty table.

    import java.util.concurrent.TimeUnit;
    import org.junit.*;
    import static org.junit.Assert.*;
    import org.openqa.selenium.*;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.interactions.Actions;


    public class practice {
      private WebDriver driver;
      private String baseUrl;

      @Before
      public void setUp() throws Exception {
        driver = new FirefoxDriver();
        baseUrl = "website link";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      }

      @Test
      public void testUntitled3() throws Exception {
        driver.get(baseUrl );


           //drag and drop first element         
            driver.findElement(By.xpath("xpath for tab 1")).click();
            WebElement drag1 = driver.findElement(By.xpath("element in tab 1"));
            WebElement drop= driver.findElement(By.xpath("emtpy table"));
            Actions action2 = new Actions(driver); 
            action2.dragAndDrop(drag1, drop).build().perform();

        //drag and drop second element 
            driver.findElement(By.xpath("open tab 2")).click();
            WebElement drag2= driver.findElement(By.id("element in tab 2"));
            WebElement drop= driver.findElement(By.xpath("same emtpy table above"));
            Actions action = new Actions(driver);   
           action.clickAndHold(drag2).moveToElement(drop2).release(drop2).perform();
 }
  @After
  public void tearDown() throws Exception {
   // driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
       }

the empty table

  <div tabindex="10" style="position: relative; overflow: hidden; height: 
    159px; width: 766px;" class="v-scrollable v-table-body-wrapper v-table- 
     body"><div style="height: 0px;" class="v-table-body-noselection"><div style="height: 10px;" class="v-table-row-spacer"></div><table class="v-table-table"><tbody></tbody></table><div style="height: 21px;" class="v-table-row-spacer"></div></div><div tabindex="-1" style="position: fixed; top: 0px; left: 0px;"></div></div>
0

In your code for second drag and drop element you have mentioned drop2 in your action but you have'nt declared the drop2 anywhere.Instead of drop2 you have mentioned drop in your second block of code. So update your code as,

//drag and drop second element 
  driver.findElement(By.xpath("open tab 2")).click();
  WebElement drag2= driver.findElement(By.id("element in tab 2"));
  WebElement drop2= driver.findElement(By.xpath("same emtpy table above"));
  Actions action = new Actions(driver);            
  action.clickAndHold(drag2).moveToElement(drop2).release(drop2).perform();

Try this will work.

| improve this answer | |
  • hi there, i found out that the xpath was entered incorrectly. When I put two drag and drop together the xpath changes. I appreciate the time you took to response to my question! – George Jun 29 '18 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.