Example usage for org.openqa.selenium Keys DELETE

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

Introduction

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

Prototype

Keys DELETE

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

Click Source Link

Usage

From source file:StoryKeyboardShortcutTests.java

@Test
public void storyKeyDelete() throws InterruptedException {

    //a. Launch story in firefox
    driver.get(/*  w  w w  .  ja va  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);

    (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   w w  w. j a v a  2s  .  c  om
    });

}

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);
    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;
                }/* ww w.j  a  va  2s .c  o m*/
            }
            assertThat(result, is("Cool car"));
            return true;
        }
    });
}

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

License:GNU Affero Public License

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

From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java

License:Apache License

/**
 * A test.//w  w w  .  j a v  a 2s . c  om
 */
@Test
public void deleteAndBackspaceKeys() {
    final WebDriver driver = getWebDriver("/javascriptPage.html");

    final WebElement element = driver.findElement(By.id("keyReporter"));

    element.sendKeys("abcdefghi");
    assertThat(element.getAttribute("value"), is("abcdefghi"));

    element.sendKeys(Keys.LEFT, Keys.LEFT, Keys.DELETE);
    assertThat(element.getAttribute("value"), is("abcdefgi"));

    element.sendKeys(Keys.LEFT, Keys.LEFT, Keys.BACK_SPACE);
    assertThat(element.getAttribute("value"), is("abcdfgi"));
}

From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java

License:Apache License

/**
 * A test.//from   ww  w.  j  a v a 2 s .  c  om
 */
@Test
public void shiftSelectionDeletes() {
    final WebDriver driver = getWebDriver("/javascriptPage.html");

    final WebElement element = driver.findElement(By.id("keyReporter"));

    element.sendKeys("abcd efgh");
    assertThat(element.getAttribute("value"), is("abcd efgh"));

    element.sendKeys(Keys.SHIFT, Keys.LEFT, Keys.LEFT, Keys.LEFT);
    element.sendKeys(Keys.DELETE);
    assertThat(element.getAttribute("value"), is("abcd e"));
}

From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java

License:Apache License

/**
 * A test./*from ww w  .j a  v a2 s . c o m*/
 */
@Test
public void chordControlHomeShiftEndDelete() {
    final WebDriver driver = getWebDriver("/javascriptPage.html");

    final WebElement result = driver.findElement(By.id("result"));
    final WebElement element = driver.findElement(By.id("keyReporter"));

    element.sendKeys("!\"#$%&'()*+,-./0123456789:;<=>?@ ABCDEFG");

    element.sendKeys(Keys.HOME);
    element.sendKeys("" + Keys.SHIFT + Keys.END);
    assertThat(result.getText(), containsString(" up: 16"));

    element.sendKeys(Keys.DELETE);
    assertThat(element.getAttribute("value"), is(""));
}

From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java

License:Apache License

/**
 * A test.//  w  w  w  .  ja  v a  2s.  c o m
 */
@Test
public void chordReveseShiftHomeSelectionDeletes() {
    final WebDriver driver = getWebDriver("/javascriptPage.html");

    final WebElement result = driver.findElement(By.id("result"));
    final WebElement element = driver.findElement(By.id("keyReporter"));

    element.sendKeys("done" + Keys.HOME);
    assertThat(element.getAttribute("value"), is("done"));

    element.sendKeys("" + Keys.SHIFT + "ALL " + Keys.HOME);
    assertThat(element.getAttribute("value"), is("ALL done"));

    element.sendKeys(Keys.DELETE);
    assertThat(element.getAttribute("value"), is("done"));

    element.sendKeys("" + Keys.END + Keys.SHIFT + Keys.HOME);
    assertThat(element.getAttribute("value"), is("done"));
    // Note: trailing SHIFT up here
    assertThat(result.getText().trim(), containsString(" up: 16"));

    element.sendKeys("" + Keys.DELETE);
    assertThat(element.getAttribute("value"), is(""));
}

From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java

License:Apache License

/**
 * A test./*ww  w.j  a  v  a2s . c  o  m*/
 */
@Test
public void nonPrintableCharactersShouldWorkWithContentEditableOrDesignModeSet() {
    final WebDriver driver = getWebDriver("/rich_text.html");

    driver.switchTo().frame("editFrame");
    final WebElement element = driver.switchTo().activeElement();
    element.sendKeys("Dishy", Keys.BACK_SPACE, Keys.LEFT, Keys.LEFT);
    element.sendKeys(Keys.LEFT, Keys.LEFT, "F", Keys.DELETE, Keys.END, "ee!");

    assertEquals("Fishee!", element.getText());
}

From source file:com.giri.target.svr.cmd.KeyCommandProcessor.java

License:Open Source License

public CharSequence getKey(String keystr) throws Exception {
    CharSequence keySeq = keystr;
    try {/*w  w  w.  j  ava 2  s.co m*/
        keySeq = Keys.valueOf(keystr);
    } catch (IllegalArgumentException e) {
        // looking for some short keys, 
        // CTRL - CONTROL
        // DEL - DELETE
        //ESCAPE
        if (keystr.indexOf('+') != -1 && keystr.length() > 1) {
            String[] keyStrs = keystr.split("\\+");
            StringBuilder sb = new StringBuilder();
            if (keyStrs != null && keyStrs.length > 0) {
                // pass for number check

                CharSequence[] kf = new CharSequence[keyStrs.length];
                int cnt = 0;
                for (String string : keyStrs) {
                    CharSequence keys = getKey(string);
                    keys = (keys == null ? string : keys);
                    kf[cnt] = keys;

                    if (cnt != 0) {
                        sb.append(" + ");
                    }
                    //                  if(keys == null){
                    //                     throw new Exception("No such key '"+string+"'");
                    //                  }
                    sb.append(keys);

                    cnt++;
                }
                keySeq = Keys.chord(kf);
            }

            System.out.println("Multikeys [" + sb.toString() + "]: " + keySeq);
        } else if ("CTRL".equalsIgnoreCase(keystr)) {
            keySeq = Keys.CONTROL;
        } else if ("DEL".equalsIgnoreCase(keystr)) {
            keySeq = Keys.DELETE;
        } else if ("EQ".equalsIgnoreCase(keystr)) {
            keySeq = Keys.EQUALS;
        } else if ("ESC".equalsIgnoreCase(keystr)) {
            keySeq = Keys.ESCAPE;
        } else {
            // check if its number key
            try {
                int num = Integer.parseInt(keystr);
                if (num >= 0 && num <= 9) {
                    keySeq = Keys.valueOf("NUMPAD" + num);
                }
            } catch (Exception e1) {
            }
        }
    }
    return keySeq;
}