Example usage for org.openqa.selenium.interactions Actions Actions

List of usage examples for org.openqa.selenium.interactions Actions Actions

Introduction

In this page you can find the example usage for org.openqa.selenium.interactions Actions Actions.

Prototype

public Actions(WebDriver driver) 

Source Link

Usage

From source file:com.mycompany.fullslidertest.FullsliderTest.java

public void addTextAndMoveIt() {
    createPresentation("Add text and move it");

    js.executeScript("$('#addtextbtn').click()");
    WebElement draggable = driver.findElement(By.xpath("//div[@id='workspace']/div[2]/div/section/div[3]"));
    waitForAction();/*from w w  w.j a v a  2 s.  c  o m*/
    new Actions(driver).dragAndDropBy(draggable, 10, 200).build().perform();
    draggable.click();

    waitForAction();
    driver.quit();
}

From source file:com.mycompany.fullslidertest.FullsliderTest.java

public void addSlideAndReorder() {
    createPresentation("Add slide and reorder it");

    js.executeScript("$('#addslidebtn').click()");
    js.executeScript("$('#addtextbtn').click()");
    WebElement draggableText = driver/*ww w .j  av a 2 s  .c  o m*/
            .findElement(By.xpath("//div[@id='workspace']/div[2]/div/section[2]/div[3]"));
    waitForAction();
    actions.dragAndDropBy(draggableText, 10, 200).build().perform();
    draggableText.click();

    WebElement draggableSlide1 = driver
            .findElement(By.xpath("//div[@id='vertical-toolbar']/div/div/div/div[1]"));
    WebElement draggableSlide2 = driver
            .findElement(By.xpath("//div[@id='vertical-toolbar']/div/div/div/div[2]"));

    int offset = draggableSlide2.getLocation().getY() - draggableSlide1.getLocation().getY();
    Actions builder = new Actions(driver);
    Actions dragAndDrop = builder.moveToElement(draggableSlide1).clickAndHold().moveByOffset(0, offset + 10)
            .pause(500); // I found the pauses were necessary to get the test working in other
    dragAndDrop.release().perform();

    waitForAction();
    driver.quit();
}

From source file:com.mycompany.fullslidertest.FullsliderTest.java

public void drawEllipseAndChangeOpacity() {
    createPresentation("Draw Ellipse and change opacity");
    waitForAction();/*from  ww  w. j av a2 s. c o  m*/

    driver.findElement(By.id("drawEllipse")).click();

    WebElement canvas = driver.findElement(By.id("canvas"));

    Actions builder = new Actions(driver);
    Action drawOnCanvas = builder.clickAndHold(canvas).moveByOffset(60, 60).release().build();
    drawOnCanvas.perform();

    driver.findElement(By.id("editEnd")).click();

    WebElement code = driver.findElement(By.xpath("//div[@id='workspace']/div[2]/div/section/div[3]"));
    actions.doubleClick(code).build().perform();
    waitForAction();

    driver.findElement(By.id("edit-fill-opacity")).click();
    driver.findElement(By.xpath("//select[@id='edit-fill-opacity']/option[7]")).click();
    driver.findElement(By.id("workspace")).click();

    waitForAction();
    driver.quit();
}

From source file:com.nabla.project.fronter.selenium.tests.helper.SeleniumHelper.java

License:Open Source License

public static void testDragDrop(final String draggable, final String droppable, String expectedResult,
        final WebDriver driver, final StringBuffer verificationErrors) {

    final WebElement source = driver.findElement(By.id(draggable));
    final WebElement target = driver.findElement(By.id(droppable));

    final Actions builder = new Actions(driver);
    builder.dragAndDrop(source, target).perform();
    try {/*www .  ja  va2s  .co  m*/
        if (null == expectedResult) {
            expectedResult = "Dropped!";
        }
        Assert.assertEquals(expectedResult, target.getText());
    } catch (final Error e) {
        verificationErrors.append(e.toString());
    }
}

From source file:com.nabla.project.fronter.selenium.tests.helper.SeleniumHelper.java

License:Open Source License

public static void testRowSelectionUsingControlKey(final List<WebElement> tableRowsInput,
        final List<WebElement> tableRowsOutput, final long expectedRows, final WebDriver driver) {

    // List<WebElement> tableRowsInput = driver.findElements(By.xpath("//table[@class='myDataTbl']/tbody/tr"));
    // Selected Row Table shows two rows selected
    // List<WebElement> tableRowsOutput = driver.findElements(By.xpath("//div[@class='icePnlGrp exampleBox']/table[@class='myDataTbl']/tbody/tr"));

    // Select second and fourth row from Table using Control Key.
    // Row Index start at 0
    final Actions builder = new Actions(driver);
    builder.click(tableRowsInput.get(1)).keyDown(Keys.CONTROL).click(tableRowsInput.get(3)).keyUp(Keys.CONTROL)
            .build().perform();//from  w  ww  .  ja  v  a 2s  .  c o m

    // Verify Selected Row Table shows X rows selected
    Assert.assertEquals(expectedRows, tableRowsOutput.size());

}

From source file:com.nabla.project.fronter.selenium.tests.helper.SeleniumHelper.java

License:Open Source License

public static void testRowSelectionUsingShiftKey(final List<WebElement> tableRowsInput,
        final List<WebElement> tableRowsOutput, final long expectedRows, final WebDriver driver) {

    // List<WebElement> tableRowsInput = driver.findElements(By.xpath("//table[@class='myDataTbl']/tbody/tr"));
    // Selected Row Table shows two rows selected
    // List<WebElement> tableRowsOutput = driver.findElements(By.xpath("//div[@class='icePnlGrp exampleBox']/table[@class='myDataTbl']/tbody/tr"));

    // Select first row to fourth row from Table using Shift Key
    // Row Index start at 0
    final Actions builder = new Actions(driver);
    builder.click(tableRowsInput.get(0)).keyDown(Keys.SHIFT).click(tableRowsInput.get(1))
            .click(tableRowsInput.get(2)).click(tableRowsInput.get(3)).keyUp(Keys.SHIFT).build().perform();

    // Verify Selected Row Table shows X rows selected
    Assert.assertEquals(expectedRows, tableRowsOutput.size());
}

From source file:com.nat.test.utils.PageNavigator.java

/**
 * Method to perform click using {@link Actions} class. Call if simple click
 * doesn't work for {@link ChromeDriver}
 *
 * @param driver/* ww  w.  j  av a2s  . com*/
 *            The driver that will be used for navigation
 * @param element
 *            Element to click
 */
public static void click(WebDriver driver, WebElement element) {
    try {
        element.click();
    } catch (org.openqa.selenium.WebDriverException e) {
        Actions action = new Actions(driver);
        action.moveToElement(element).perform();
        action.click().perform();
    }
}

From source file:com.NFHS.PageObjects.UserAccountPage.java

public void courseEvaluation() throws Exception {
    Actions builder = new Actions(driver);
    builder.click(webElementProperty("evaluation_rb1")).perform();
    builder.click(webElementProperty("evaluation_rb2")).perform();
    builder.click(webElementProperty("evaluation_rb3")).perform();
    builder.click(webElementProperty("evaluation_rb4")).perform();
    builder.click(webElementProperty("evaluation_rb5")).perform();
    builder.click(webElementProperty("evaluation_rb6")).perform();

}

From source file:com.NFHS.PageObjects.UserAccountPage.java

public void coursePage() throws Exception {
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    webElementProperty("mycourses").click();
    webElementProperty("completecoursebutton").click();

    if (webElementProperty("introduction").getText().equals("Introduction")) {
        System.out.println("next button is disabled");
        System.out.println(webElementProperty("nextbutton").isEnabled());
        Actions builder = new Actions(driver);
        builder.click(webElementProperty("1strdbtn")).perform();

        if (webElementProperty("cc_submitbutton").isEnabled()) {
            driver.manage().timeouts().implicitlyWait(5, TimeUnit.MINUTES);
            webElementProperty("cc_submitbutton").click();
        }/* w w w . java  2 s .  c  o  m*/
        //2 question selected
        Thread.sleep(2000);
        builder.click(webElementProperty("1strdbtn")).perform();

        if (webElementProperty("cc_submitbutton").isEnabled()) {
            webElementProperty("cc_submitbutton").click();
        }
        Thread.sleep(2000);
        //3 question selected
        builder.click(webElementProperty("1strdbtn")).perform();
        if (webElementProperty("cc_submitbutton").isEnabled()) {
            webElementProperty("cc_submitbutton").click();
        }
        Thread.sleep(2000);
        //4 question selecte
        builder.click(webElementProperty("1strdbtn")).perform();

        if (webElementProperty("cc_submitbutton").isEnabled()) {
            webElementProperty("cc_submitbutton").click();
        }

        Thread.sleep(2000);
        //5 question selected
        builder.click(webElementProperty("1strdbtn")).perform();

        if (webElementProperty("cc_submitbutton").isEnabled()) {
            webElementProperty("cc_submitbutton").click();
        }

        Thread.sleep(2000);
        //6 question selected

        builder.click(webElementProperty("1strdbtn")).perform();

        if (webElementProperty("cc_submitbutton").isEnabled()) {
            webElementProperty("cc_submitbutton").click();
        }

        Thread.sleep(2000);
        //7 question selected
        builder.click(webElementProperty("1strdbtn")).perform();

        if (webElementProperty("cc_submitbutton").isEnabled()) {
            webElementProperty("cc_submitbutton").click();
        }

        Thread.sleep(2000);
        //8 question selected
        builder.click(webElementProperty("1strdbtn")).perform();

        if (webElementProperty("cc_submitbutton").isEnabled()) {
            webElementProperty("cc_submitbutton").click();
        }
        Thread.sleep(2000);
        //9 question selected
        builder.click(webElementProperty("1strdbtn")).perform();

        if (webElementProperty("cc_submitbutton").isEnabled()) {
            webElementProperty("cc_submitbutton").click();
        }
        Thread.sleep(2000);
        //10 question selected
        builder.click(webElementProperty("1strdbtn")).perform();
        if (webElementProperty("cc_submitbutton").isEnabled()) {
            webElementProperty("cc_submitbutton").click();
        }
        Thread.sleep(2000);
        //11 question selected
        builder.click(webElementProperty("1strdbtn")).perform();
        if (webElementProperty("cc_submitbutton").isEnabled()) {
            webElementProperty("cc_submitbutton").click();
        }
        Thread.sleep(1000);
        nextButtonClick();

    }

    /*System.out.println("Before 4 if enabled");
    driver.manage().timeouts().implicitlyWait(2, TimeUnit.MINUTES);
    if(webElementProperty("3breadcrumb").isEnabled() || !webElementProperty("4breadcrumb").isEnabled())
    {
       driver.manage().timeouts().implicitlyWait(2, TimeUnit.MINUTES);
    WebElement nextbtn=webElementProperty("nextbutton");
    if(nextbtn.isEnabled())
    {
       nextbtn.click();
    }
    }
            
     System.out.println("before 5 is enabled"); 
             
     driver.manage().timeouts().implicitlyWait(2, TimeUnit.MINUTES);
       if(webElementProperty("4breadcrumb").isEnabled() || !webElementProperty("5breadcrumb").isEnabled())
       {
    driver.manage().timeouts().implicitlyWait(2, TimeUnit.MINUTES);
       WebElement nextbtn=webElementProperty("nextbutton");
       if(nextbtn.isEnabled())
       {
    nextbtn.click();
       }
       } 
            
      Thread.sleep(2000);
              
               
             
              
     oneEnabledTwoDisabled();
              
      twoEnabledThreeDisabled();
              
       isThreeEnabled();
               
      oneEnabledTwoDisabled();
              
      twoEnabledThreeDisabled();
              
      isThreeEnabled();
              
      nextButtonClick();
              
      twoEnabledThreeDisabled();
              
      threeEnabledFourDisabled();
              
      isFourEnabled();
              
      oneEnabledTwoDisabled();
              
      twoEnabledThreeDisabled();
              
      threeEnabledFourDisabled();
              
      isFourEnabled();
              
      oneEnabledTwoDisabled();
             
      isTwoEnabled();
              
      oneEnabledTwoDisabled();
              
      twoEnabledThreeDisabled();
              
      threeEnabledFourDisabled();
              
      isFourEnabled();
              
      oneEnabledTwoDisabled();
              
      webElementProperty("unit3_Img1").click();
      webElementProperty("unit3_Img2").click();
              
      nextButtonClick();
              
      isThreeEnabled();
              
      nextButtonClick();
              
      nextButtonClick();
              
      isOneEnabled();
              
      if(webElementProperty("1breadcrumb").isEnabled())
       {
               
       Thread.sleep(5000);
         //1 question selected
         Actions builder =new Actions(driver);
       builder.click(webElementProperty("1strdbtn")).perform();
            
               
       if(webElementProperty("cc_submitbutton").isEnabled())
       {
    webElementProperty("cc_submitbutton").click();
       }
       //2 question selected
       Thread.sleep(2000);
       builder.click(webElementProperty("1strdbtn")).perform();
               
       if(webElementProperty("cc_submitbutton").isEnabled())
       {
    webElementProperty("cc_submitbutton").click();
       }
       Thread.sleep(2000);
       builder.click(webElementProperty("1strdbtn")).perform();
       //3 question selected
               
       if(webElementProperty("cc_submitbutton").isEnabled())
       {
    webElementProperty("cc_submitbutton").click();
       }
       Thread.sleep(2000);
       //4 question selecte
       builder.click(webElementProperty("1strdbtn")).perform();
               
       if(webElementProperty("cc_submitbutton").isEnabled())
       {
    webElementProperty("cc_submitbutton").click();
       }
               
       Thread.sleep(2000);
       //5 question selected
        builder.click(webElementProperty("1strdbtn")).perform();
            
        if(webElementProperty("cc_submitbutton").isEnabled())
    {
       webElementProperty("cc_submitbutton").click();
    }
            
            
    Thread.sleep(2000);
       //6 question selected
            
    builder.click(webElementProperty("1strdbtn")).perform();
            
    if(webElementProperty("cc_submitbutton").isEnabled())
        {
     webElementProperty("cc_submitbutton").click();
        }
            
    Thread.sleep(2000);
       //7 question selected
      builder.click(webElementProperty("1strdbtn")).perform();
               
      if(webElementProperty("cc_submitbutton").isEnabled())
       {
          webElementProperty("cc_submitbutton").click();
       }
               
       Thread.sleep(2000);
       //8 question selected
         builder.click(webElementProperty("1strdbtn")).perform();
                  
         if(webElementProperty("cc_submitbutton").isEnabled())
          {
             webElementProperty("cc_submitbutton").click();
          }
          Thread.sleep(2000);
       //9 question selected
            builder.click(webElementProperty("1strdbtn")).perform();
                     
            if(webElementProperty("cc_submitbutton").isEnabled())
             {
                webElementProperty("cc_submitbutton").click();
             }
             Thread.sleep(2000);
       //10 question selected
               builder.click(webElementProperty("1strdbtn")).perform();
               if(webElementProperty("cc_submitbutton").isEnabled())
                {
                   webElementProperty("cc_submitbutton").click();
                }
                Thread.sleep(2000);
       //11 question selected
                  builder.click(webElementProperty("1strdbtn")).perform();
                           
                  if(webElementProperty("cc_submitbutton").isEnabled())
                   {
                      webElementProperty("cc_submitbutton").click();
                   }
                  WebElement nextbtn1=webElementProperty("nextbutton");
                   if(nextbtn1.isEnabled())
                   {
                      nextbtn1.click();
                   }
               
               
    }
              
        JavascriptExecutor js=(JavascriptExecutor)driver;
        js.executeScript("scroll(0,200)");
                
        nextButtonClick();
                
        oneEnabledTwoDisabled();
                
        isTwoEnabled();
                
        isOneEnabled();
        isOneEnabled();
                
        courseEvaluation();
                
        webElementProperty("evaluation_submit").click();
                
        webElementProperty("download_certificate").click();*/

}

From source file:com.opera.core.systems.DriverKeysTest.java

License:Apache License

@Test
public void testSingleCharacter() {
    new Actions(driver).sendKeys("a").build().perform();
    assertEquals("a", fieldOne.getAttribute("value"));
}