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:edu.samplu.common.WebDriverLegacyITBase.java

License:Educational Community License

/**
 * {@link Actions#moveToElement(org.openqa.selenium.WebElement)}
 * @param by//from ww w.  j  ava 2  s. co m
 */
public void fireMouseOverEvent(By by) {
    Actions builder = new Actions(driver);
    Actions hover = builder.moveToElement(driver.findElement(by));
    hover.perform();
}

From source file:EndToEnd.BFUIJobsExcnVldtnTest.java

License:Apache License

/**
 *  testStep2BFUIImagerySubmit() to accomplish testing 
 *  of below functions of BF UI:/*ww  w  .ja  v  a2  s  . co m*/
 *  a) After user successfully logs in to BF UI Application
 *  b) Selection of Create Job link
 *  c) On the Canvas, specifying the geographic area
 *  d) Entering the input data into the Search imagery request form.
 *  e) Submit the form successfully 
 *  
 * @throws Exception
 */
@Test
public void testStep2BFUIImagerySubmit() throws Exception {
    String message = "";
    System.out.println(">>>> In BFUIJobsExcnVldtn.testStep2BFUIImagerySubmit() <<<<");

    driver.findElement(By.className("Navigation-linkCreateJob")).click();
    System.out.println(">> After requesting create job form");
    Thread.sleep(200);

    WebElement canvas = driver.findElement(By.cssSelector(".PrimaryMap-root canvas"));
    Thread.sleep(200); //To avoid any race condition

    Actions builder = new Actions(driver);
    builder.moveToElement(canvas, 900, 400).click().build().perform();
    canvas.click();
    Thread.sleep(1000); //To avoid any race condition

    builder.moveToElement(canvas, 400, 100).click().build().perform();
    canvas.click();
    Thread.sleep(200);

    System.out.println(">> After selecting bounding box as geographic search criteria area on canvas");
    Thread.sleep(5000); //To avoid any race condition

    // populating API key on the Imagery search form
    driver.findElement(By.cssSelector("input[type=\"password\"]")).clear();
    driver.findElement(By.cssSelector("input[type=\"password\"]")).sendKeys("27c9b43f20f84a75b831f91bbb8f3923");
    Thread.sleep(1000);
    // Changing From date field for Date of Capture imagery search criteria
    driver.findElement(By.cssSelector("input[type=\"text\"]")).clear();
    driver.findElement(By.cssSelector("input[type=\"text\"]")).sendKeys("2017-01-29");
    Thread.sleep(500); //To avoid any race condition
    driver.findElement(By
            .cssSelector("label.CatalogSearchCriteria-captureDateTo.forms-field-normal > input[type=\"text\"]"))
            .clear();
    driver.findElement(By
            .cssSelector("label.CatalogSearchCriteria-captureDateTo.forms-field-normal > input[type=\"text\"]"))
            .sendKeys("2017-01-31");
    Thread.sleep(500);
    new Select(driver.findElement(By.cssSelector("select"))).selectByVisibleText("RapidEye (Planet)");
    Thread.sleep(500);
    // Submitting the search criteria
    driver.findElement(By.cssSelector("button[type=\"submit\"]")).click();
    System.out.println(">> After entering data and submitting Source Imagery search form");
    Thread.sleep(16000); //Pause before exiting this test

}

From source file:EndToEnd.BFUIJobsExcnVldtnTest.java

License:Apache License

/**
 *  testStep3BFSIResponsePopup() to accomplish testing of below functions of BF UI:
 *  a) After user enter the search criteria for image search catalog and submits
 *  b) Move to the map canvas panel//from  w  w w .ja  v a 2s. co m
 *  c) Select the response image jpg file to display the pop up
 *     with properties of the selected response image
 *  
 * @throws Exception
 */
@Test
public void testStep3BFSIResponsePopup(int cordArrayIndex) throws Exception {
    String message = "";
    System.out.println(">>>> In BFUIJobsExcnVldtn.testStep3BFSIResponsePopup() <<<<");
    Actions builder = new Actions(driver);
    WebElement canvas = driver.findElement(By.cssSelector(".PrimaryMap-root canvas"));
    WebElement search = driver.findElement(By.className("PrimaryMap-search"));
    Thread.sleep(200); //To avoid any race condition
    builder.moveToElement(search, 0, 0).click().build().perform();
    //canvas.click(); // With or without jenkins build fails
    Thread.sleep(1000); //To avoid any race condition
    System.out.println("Focusing on " + cordCity[cordArrayIndex][0] + "");
    driver.findElement(By.name("coordinate")).sendKeys(cordCity[cordArrayIndex][1]);
    Thread.sleep(200); //To avoid any race condition
    driver.findElement(By.name("coordinate")).submit();
    builder.moveToElement(canvas).click().build().perform();
    System.out.println("After moving to canvas and selecting image jpg on canvas");

    //       //By clickLinkElem = By.xpath("//*[@title='LC81950572015002LGN00']");
    //By clickLinkElem = By.xpath("//*[@title='LC82040522016276LGN00']");
    //if (this.isElementPresent(clickLinkElem)) {
    // Ensuring the properties windows is displayed for the image selected
    // LANDSAT image id for selected image should be the title.
    // driver.findElement(By.xpath("//*[@title='LC82040522016276LGN00']"));
    //driver.findElement(By.xpath("//*[@title='LC81210602015204LGN00']"));
    //System.out.println("After validating properties popup is displayed for the response image selected");
    //}

    Thread.sleep(2000); //Pause before exiting this test

}

From source file:entities.GPTPlanet.java

@Override
public void openAd() {
    openAdsPage();//  w  w  w  . j av a2 s.co m
    ArrayList<String> links = getAllAds();
    for (String link : links) {
        int timeout = 30;
        appendLog("-- Opening Ad: " + link);
        driver.get(homeUrl + link);
        while (timeout > 0) {
            List<WebElement> elements = null;
            try {
                elements = driver.findElements(
                        By.xpath("//div[@id='surfbar' and not(contains(@style,'display: none'))]"));
            } catch (UnhandledAlertException ex) {
                appendLog("\tError: UnhandledAlertException");
                elements = driver.findElements(
                        By.xpath("//div[@id='surfbar' and not(contains(@style,'display: none'))]"));
            }
            if (elements.size() > 0) {
                WebElement e = elements.get(0);
                if (e.getText().contains("Wait please") || (e
                        .findElements(By.xpath(
                                "./div/div[@id='progressbar' and not(contains(@style,'display: none'))]"))
                        .size() > 0)) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(Neobux.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    timeout--;
                } else if (e.getText().contains("Thanks for watching!")
                        || e.getText().contains("Invalid Advertisement")
                        || e.getText().contains("already visited")) {
                    break;
                } else if (e
                        .findElements(
                                By.xpath("./div[@id='focusoff' and not(contains(@style,'display: none'))]"))
                        .size() > 0) {
                    appendLog("--- Off Focus...... ---");
                    driver.switchTo().window(getCurrentWindow());
                    e.findElement(By.xpath("./a")).click();
                } else {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(Neobux.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    timeout--;
                    if (timeout < (timeout / 3)) {
                        driver.navigate().refresh();
                    }
                }
            } else if (driver
                    .findElements(By.xpath("//div[@id='vnumbers' and not(contains(@style,'display: none'))]"))
                    .size() > 0) {
                try {
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(Neobux.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    WebElement element = driver
                            .findElement(By.xpath("//*[@id=\"vnumbers\"]/table/tbody/tr/td[2]"));
                    Point point = element.getLocation();
                    File ss = (File) ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
                    BufferedImage src = ImageIO.read(ss);
                    BufferedImage screen = src.getSubimage(point.getX(), point.getY(),
                            element.getSize().getWidth(), element.getSize().getHeight());
                    StaticImageScreenRegion region = new StaticImageScreenRegion(screen);
                    boolean found = false;
                    for (File file : new File("./src/imgs").listFiles()) {
                        if (file.isFile()) {
                            for (ScreenRegion match : region.findAll(new ImageTarget(ImageIO.read(file)))) {
                                found = true;

                                System.out.println("---location: " + point + " - " + element.getSize());
                                System.out.println("---match: " + match.getCenter());
                                System.out.println("-order: " + ((match.getCenter().getX() / 50) + 1));
                                System.out
                                        .println("- target: " + (point.getX() + 50 + match.getCenter().getX()));
                                new Actions(driver).moveToElement(element, 0, 0)
                                        .moveByOffset(match.getCenter().getX(), match.getCenter().getY())
                                        .click().perform();
                                break;
                            }
                        }
                        if (found) {
                            break;
                        }
                    }
                    if (!found) {
                        ImageIO.write(screen, "PNG", new File("./src/imgs/detected/notfound-"
                                + link.substring(link.lastIndexOf("=") + 1) + ".png"));
                    }
                    //                        break;
                } catch (Exception ex) {
                    Logger.getLogger(ScarletClicks.class.getName()).log(Level.SEVERE, null, ex);
                }

            } else {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Neobux.class.getName()).log(Level.SEVERE, null, ex);
                }
                timeout--;
                if (timeout < (timeout / 3)) {
                    driver.navigate().refresh();
                }
            }
        }
    }
}

From source file:exercise.component.runner.java

public static void selectCategoryDropdown(String optionName) throws InterruptedException {

    WebElement category = driver.findElement(By.name("test"));
    java.util.List<WebElement> opts = category.findElements(By.tagName("option"));
    category.click();// ww w . java 2s . c  om
    Iterator iter = opts.iterator();
    while (iter.hasNext()) {
        WebElement opt = (WebElement) iter.next();
        if (opt.getAttribute("value").equals(optionName)) {
            Actions act = new Actions(driver);
            act.moveToElement(opt).click().build().perform();
            //opt.click();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            break;
        }
    }

}

From source file:fr.lip6.segmentations.BrowserRep.java

License:Open Source License

public BrowserRep(WebDriver driver, DesiredCapabilities capabilities, String desc) {
    this.driver = driver;
    this.capabilities = capabilities;
    this.desc = desc;
    this.actions = new Actions(this.driver);
    if (driver instanceof JavascriptExecutor) {
        this.js = (JavascriptExecutor) driver;
    }/*from   www.  jav a  2s .c o  m*/
}

From source file:GlennsPack.GlennWebAPI.Bot2048.java

License:Open Source License

public Bot2048() {
    System.setProperty("webdriver.chrome.driver", "C:/Users/Glenn/Downloads/chromedriver/chromedriver.exe");
    WebDriver driver = new ChromeDriver();

    driver.manage().window().setSize(new Dimension(2000, 800));

    driver.get("http://annimon.github.io/16384/");

    //      try {
    //         Thread.sleep(2000);
    //      } catch (Exception e) {
    //         // FIXME: handle exception
    //      }// www.  j av  a  2s .  c om
    //      
    WebElement element = driver.findElement(By.xpath("/html/body/div"));
    //            ("/html/body/div/div[2]"));

    Actions actions = new Actions(driver);
    actions.moveToElement(element);
    actions.click();
    CharSequence[] array = { Keys.ARROW_DOWN, Keys.ARROW_LEFT, Keys.ARROW_RIGHT };
    for (int i = 0; i < 1000000; i++) {
        Random random = new Random();
        actions.sendKeys(array[random.nextInt(3)]);
        ;
        actions.sendKeys(Keys.ARROW_DOWN);
        actions.build().perform();
        try {
            //         Thread.sleep(1);
        } catch (Exception e) {
            // FIXME: handle exception
        }
    }
}

From source file:GlennsPack.GlennWebAPI.Keybr.java

License:Open Source License

public void runer(WebDriver driver) {

    driver.findElement(By.className("Tour-close")).click();

    System.out.println("CLICKED");
    ////from  ww w .j  av a2  s  .  c om
    try {

        driver.findElement(By.id("Practice-textInput")).click();
        Thread.sleep(1000);
        WebElement element = driver.findElement(By.id("Practice"));

        Actions actions = new Actions(driver);
        actions.moveToElement(element);
        actions.click();

        String abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz[]-.,?!()\"'";

        Robot robot = new Robot();

        for (int i1 = 0; i1 < 30; i1++) {

            try {
                for (int i = 0; i < 200; i++) {

                    String currLetter = driver
                            .findElement(By.cssSelector("span.TextInput-item:nth-child(" + (i + 1) + ")"))
                            .getText();
                    System.out.println(currLetter);

                    if (!abc.contains(currLetter)) {
                        currLetter = " ";
                        System.out.println("SPACE");
                        i++;
                    }

                    Thread.sleep(25);

                    robot.keyPress(KeyEvent.getExtendedKeyCodeForChar(currLetter.charAt(0)));
                    actions.build().perform();
                    robot.keyRelease(KeyEvent.getExtendedKeyCodeForChar(currLetter.charAt(0)));
                }
            } catch (Exception e) {
                System.out.println("Another row done");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.PageNavigation.PageNavigation3.java

License:Apache License

public void processDriver(WebDriver driver) {
    try {/* w ww .  j  a v a  2  s  .  c o  m*/

        System.out.println("Page title is: " + driver.getTitle());

        String url = driver.getCurrentUrl();
        WebDriverWait wait = new WebDriverWait(driver, 5);
        By targetBy = By.id("");
        By targetPath = By.id("");

        if (url.contains("armslist")) {
            targetBy = By.id("termsagreement");
            targetPath = By.xpath("//button[span='I Agree']");

            WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(targetBy));
            element = element.findElement(targetPath);
            element.click();
        } else if (url.contains("tennesseegunexchange")) {
            System.out.println("url contains msgun!!!!!");
            targetBy = By.id("cw_enter_link");

            WebElement ele = driver.findElement(targetBy);
            Actions action = new Actions(driver);

            action.moveToElement(ele).build().perform();
            ele.click();
        }
    } catch (Exception e) {
        System.out.println(e.toString());
    }

    //System.out.println("=====DEBUG: click success!");

}