Example usage for org.openqa.selenium Keys CONTROL

List of usage examples for org.openqa.selenium Keys CONTROL

Introduction

In this page you can find the example usage for org.openqa.selenium Keys CONTROL.

Prototype

Keys CONTROL

To view the source code for org.openqa.selenium Keys CONTROL.

Click Source Link

Usage

From source file:StoryKeyboardShortcutTests.java

@Test
public void storyKeyDelete() throws InterruptedException {

    //a. Launch story in firefox
    driver.get(//from   w w w .  jav  a 2 s. c o  m
            "http://tanveer-pc:9724/web/story/story.html?debug&storyhub=tanveer-pc&gh=Guest/@tanveer-pc&pilot=tanveer-pc&preview=tanveer-pc&mediaservice=tanveer-pc");
    //driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

    WebDriverWait wait = new WebDriverWait(driver, 15);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']")));

    //Close the license popup
    WebElement okButton = driver.findElement(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']"));
    okButton.click();

    //Click on Media tab
    WebElement uploadButton = driver.findElement(
            By.xpath("html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[1]/div[1]/div/table/tbody/tr/td"));
    uploadButton.click();

    //From storytab double click on story named 'storytest'
    Thread.sleep(2000);
    WebElement storytest = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div/div[3]"));
    storytest.click();
    WebElement storytest1 = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div/div[3]"));

    storytest1.click();
    storytest1.click();

    Thread.sleep(3000);
    //Select the video element in timeline div[class="thumbnailStrip"]
    WebElement timelinebar = driver.findElement(By.cssSelector("div[class='thumbnailStrip']"));
    timelinebar.click();

    Thread.sleep(2000);

    WebElement timebarnumber = driver.findElement(
            By.xpath("//div[contains(@style,'POSITION') and @eventproxy='sta_timeline_cursorlabel_1']"));
    final String timevalue = timebarnumber.getText();

    WebElement timebarnumber1 = driver.findElement(
            By.xpath("//div[contains(@style,'POSITION') and @eventproxy='sta_timeline_cursorlabel_1']"));
    final String timevalue1 = timebarnumber.getText();

    Actions action = new Actions(driver);

    //Asserting if presence of element shows false after deletion button is pressed
    action.sendKeys(Keys.DELETE).build().perform();
    Boolean isPresent2 = driver.findElements(By.cssSelector("div[class='thumbnailStrip']")).size() > 0;
    Assert.assertEquals(false, isPresent2);

    // Undoing the change to timeline by pressing 'CTRL + Z'
    Thread.sleep(2000);
    Actions action2 = new Actions(driver);
    action2.keyDown(Keys.CONTROL).sendKeys(String.valueOf('\u007A')).perform();

    /*
    Thread.sleep(2000);
    Actions action = new Actions(driver);
    //String selectAll = Keys.chord(Keys.CONTROL, "a");
            
    action.sendKeys(".").perform();
    // action.sendKeys(selectAll).build().perform();
    //action.sendKeys(Keys.getKeyFromUnicode('selectAll')).build().perform();
    */

}

From source file:seleniumTester.java

@Test
public void test3() {
    WebElement element = driver.findElement(By.id("filter"));
    element.sendKeys(Keys.CONTROL + "a");
    element.sendKeys(Keys.DELETE);/*from  w  ww .j av  a 2  s  .c  om*/

    (new WebDriverWait(driver, WAIT_MAX)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            WebElement e = d.findElement(By.tagName("tbody"));
            List<WebElement> rows = e.findElements(By.tagName("tr"));

            Assert.assertThat(rows.size(), is(5));
            return rows.size() == 5;
        }
    });

}

From source file:seleniumTester.java

@Test
public void test_5() {
    List<WebElement> tds = driver.findElement(By.id("tbodycars")).findElements(By.cssSelector("tr")).get(0)
            .findElements(By.tagName("td"));
    tds.get(7).findElements(By.tagName("a")).get(0).click();
    WebElement element = driver.findElement(By.id("description"));
    element.sendKeys(Keys.CONTROL + "a");
    element.sendKeys(Keys.DELETE);/*from w w w.  ja v a 2s  . c  om*/
    element.sendKeys("Cool car");
    driver.findElement(By.id("save")).click();

    (new WebDriverWait(driver, WAIT_MAX)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            WebElement e = d.findElement(By.tagName("tbody"));
            List<WebElement> rows = e.findElements(By.tagName("tr"));
            String result = null;
            for (int i = 0; i < rows.size(); i++) {
                if (rows.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) {
                    result = rows.get(i).findElements(By.tagName("td")).get(5).getText();
                    break;
                }
            }
            assertThat(result, is("Cool car"));
            return true;
        }
    });
}

From source file:application.Main.java

License:Open Source License

public static void appSingleThread(Globals GLOBALS) {
    LinkedList<String> list = Input.readFacebookPostIds(GLOBALS.FILENAME);
    if (GLOBALS.RANDOM) {
        Collections.shuffle(list);
    }//w  ww.  j  av a 2 s.  c  om
    String email = GLOBALS.fb_eamil;
    String pass = GLOBALS.password;
    WebDriver driver = new FirefoxDriver(); // The Firefox driver supports javascript 
    Autenticate.perform(driver, email, pass);
    try {
        Thread.sleep(Globals.TIME_TO_LOGIN_IN_FB_MS);
    } catch (Exception ex) {
        System.out.println("InterruptedException in crawl.run()");
        ex.printStackTrace();
        System.exit(-1);
    }
    for (String post_id : list) {
        System.out.println("\n****** STARTING NEW TREE: " + post_id + "******");
        try {
            //OPEN NEW TAB
            WebElement body = driver.findElement(By.tagName("body"));
            body.sendKeys(Keys.CONTROL + "t");
            Tree post = new Tree(post_id, GLOBALS);
            boolean result = post.crawl(driver);
            if (result) {
                post.prune();
                post.print();
                post.printEdgeList();
                System.out.println("****** TREE " + post_id + " ACCOMPLISHED ******");
            } else {
                body.sendKeys(Keys.CONTROL + "w");
                System.out.println("****** TREE " + post_id + " FAILED ******");
            }
            //SWITCH TAB
            ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
            driver.switchTo().window(tabs.get(tabs.size() - 1));
        } catch (Exception e) {
            System.out.println("****** TREE " + post_id + " FAILED ******");
            System.out.println("EXCEPTION in MAIN " + e);
            System.out.println("...RESTARTING APPLICATION AFTER 1 minute APPLICATION...");
            driver.quit();
            try {
                Thread.sleep(Globals.ONE_MINUTE);
            } catch (Exception ex) {
                System.out.println("InterruptedException in crawl.run()");
                ex.printStackTrace();
                System.exit(-1);
            }
            driver = new FirefoxDriver(); // The Firefox driver supports javascript 
            Autenticate.perform(driver, email, pass);
        }
    }
    driver.quit();
}

From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.WebTextField.java

License:Open Source License

private String getValueToSend(String value) {
    String finalValue = Keys.chord(Keys.CONTROL, "a") + value + Keys.chord(Keys.TAB);
    return finalValue;
}

From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.WebDriverRunner.java

License:Open Source License

public File saveScreenshotTo(String fileName, boolean generateSource) {
    File screenshotFile = new File(fileName);

    screenshotFile.getParentFile().mkdirs();

    driver.manage().window().maximize();

    File screenshot = null;/*from  w  ww . j  a  v  a  2s  .  com*/

    if (BehaveConfig.getRunner_screenShotZoomout() != 0) {
        WebElement html = driver.findElement(By.tagName("html"));

        for (int x = 0; x < BehaveConfig.getRunner_screenShotZoomout(); x++) {
            html.sendKeys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT));
        }

        screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        html.sendKeys(Keys.chord(Keys.CONTROL, "0"));
    } else {
        screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    }

    if (screenshot != null) {
        try {
            FileUtils.copyFile(screenshot, new File(screenshotFile.getAbsolutePath()));

            if (generateSource) {
                writeHtmlFile(screenshotFile.getAbsolutePath());
            }
        } catch (IOException e) {
            throw new BehaveException(message.getString("exception-save-screenshot"), e);
        }
    }

    return screenshotFile;
}

From source file:browsermator.com.NextTabAction.java

@Override
public void RunAction(WebDriver driver) {
    try {/*from   w w  w.  j  a v a 2  s.c o m*/
        //       Actions actions = new Actions(driver);
        String current_tab_handle = driver.getWindowHandle();

        driver.findElement(By.cssSelector("body")).sendKeys(Keys.chord(Keys.CONTROL, Keys.TAB));
        // actions.keyDown(Keys.CONTROL).sendKeys(Keys.TAB).keyUp(Keys.CONTROL).build().perform();

        Set<String> tab_handles = driver.getWindowHandles();
        int current_tab_index = 0;

        int number_of_tabs = tab_handles.size();
        int tabs_counted = 1;
        for (String handle : tab_handles) {
            if (handle.equals(current_tab_handle)) {

                if (tabs_counted == number_of_tabs) {
                    // last tab
                    current_tab_index = 0;
                } else {
                    current_tab_index = tabs_counted;
                }
            }

            tabs_counted++;
        }

        driver.switchTo().window(tab_handles.toArray()[current_tab_index].toString());

        this.Pass = true;
    } catch (Exception ex) {
        this.Pass = false;
    }
}

From source file:cc.kune.selenium.PageObject.java

License:GNU Affero Public License

/**
 * Clear field.//from ww  w. j  a  v a 2  s.  c o  m
 * 
 * @param elem
 *          the elem
 */
protected void clearField(final WebElement elem) {
    elem.sendKeys(Keys.chord(Keys.CONTROL, "a"), Keys.DELETE);
}

From source file:com.atanas.kanchev.testframework.selenium.handlers.Interact.java

License:Apache License

/**
 * {@inheritDoc}/*from   w  ww.  ja  v  a 2  s. c o m*/
 */
@Override
public Interact selectAll() {
    ((SeleniumContext<WebDriver>) context().getCurrentContext()).getCurrentElement()
            .sendKeys(Keys.chord(Keys.CONTROL, "a"));
    return this;
}

From source file:com.atanas.kanchev.testframework.selenium.handlers.Interact.java

License:Apache License

/**
 * {@inheritDoc}//  w  ww.j  a va 2s .  c  o m
 */
@Override
public Interact copy() {
    ((SeleniumContext<WebDriver>) context().getCurrentContext()).getCurrentElement()
            .sendKeys(Keys.chord(Keys.CONTROL, "c"));
    return this;
}