Example usage for org.openqa.selenium WebElement getText

List of usage examples for org.openqa.selenium WebElement getText

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement getText.

Prototype

String getText();

Source Link

Document

Get the visible (i.e.

Usage

From source file:com.francetelecom.clara.cloud.webapp.acceptancetest.pages.EnvironmentCreationPage.java

License:Apache License

private List<String> getOptions(Select select) {
    List<String> options = new ArrayList<String>();
    for (WebElement element : select.getOptions()) {
        options.add(element.getText());

    }//from   ww w .j a v a 2  s . co m
    return options;
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlColorInputTest.java

License:Apache License

/**
 * Verifies that a asText() returns the value string.
 * @throws Exception if the test fails/*  www .ja  v a 2 s .c  o m*/
 */
@Test
public void asText() throws Exception {
    final String htmlContent = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'>\n"
            + "  <input type='color' name='foo' id='foo' value='#ff0000'>\n" + "</form></body></html>";

    final WebDriver driver = loadPage2(htmlContent);

    final WebElement input = driver.findElement(By.id("foo"));
    assertEquals("", input.getText());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlElement2Test.java

License:Apache License

/**
 * @throws Exception if the test fails//from w  w  w  .  j av  a  2  s .c o m
 */
@Test
@NotYetImplemented
//TODO: fails because of HTMLElement.getContentEditable doesn't detect DomElement.ATTRIBUTE_VALUE_EMPTY
// this could be a general attribute issue
public void contentEditable() throws Exception {
    final String html = "<html>\n" + "<body contentEditable><p>initial</p></body>\n" + "</html>";

    final WebDriver driver = loadPage2(html);
    final WebElement body = driver.findElement(By.xpath("//body"));
    body.clear();
    body.sendKeys("something");
    assertEquals("something", body.getText());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlElement2Test.java

License:Apache License

/**
 * @throws Exception if an error occurs//from w w w . j a va 2s. c  o  m
 */
@Test
@Alerts(DEFAULT = "down: 16,0 down: 49,0 press: 33,33 up: 49,0 up: 16,0"
        + " down: 16,0 down: 220,0 press: 124,124 up: 220,0 up: 16,0", FF = "down: 16,0 down: 49,0 press: 0,33 up: 49,0 up: 16,0"
                + " down: 16,0 down: 220,0 press: 0,124 up: 220,0 up: 16,0")
//https://github.com/SeleniumHQ/selenium/issues/639
@BuggyWebDriver(Browser.FF)
public void shiftKeys() throws Exception {
    final String html = "<html><head><script>\n" + "  function appendMessage(message) {\n"
            + "    document.getElementById('result').innerHTML += message + ' ';\n" + "  }\n"
            + "</script></head>\n" + "<body >\n"
            + "  <input id='input1' onkeyup=\"appendMessage('up: ' + event.keyCode + ',' + event.charCode)\" "
            + "onkeypress=\"appendMessage('press: ' + event.keyCode + ',' + event.charCode)\" "
            + "onkeydown=\"appendMessage('down: ' + event.keyCode + ',' + event.charCode)\"><br>\n"
            + "<p id='result'></p>\n" + "</body></html>";

    final WebDriver driver = loadPage2(html);
    final WebElement input = driver.findElement(By.id("input1"));
    final WebElement result = driver.findElement(By.id("result"));
    input.sendKeys("!|");
    assertEquals(getExpectedAlerts()[0], result.getText());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlFileInputTest.java

License:Apache License

/**
 * Verifies that a asText() returns an empty string.
 * @throws Exception if the test fails//from w w w . j  a va  2 s. co m
 */
@Test
public void asText() throws Exception {
    final String htmlContent = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'>\n"
            + "  <input type='file' name='foo' id='foo' value='bla'>\n" + "</form></body></html>";

    final WebDriver driver = loadPage2(htmlContent);

    final WebElement input = driver.findElement(By.id("foo"));
    assertEquals("", input.getText());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlHiddenInputTest.java

License:Apache License

/**
 * Verifies that a asText() returns an empty string.
 * @throws Exception if the test fails//from www .j a  va2s .c  o  m
 */
@Test
public void asText() throws Exception {
    final String htmlContent = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'>\n"
            + "  <input type='hidden' name='foo' id='foo' value='bla'>\n" + "</form></body></html>";

    final WebDriver driver = loadPage2(htmlContent);

    final WebElement input = driver.findElement(By.id("foo"));
    assertEquals("", input.getText());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlNumberInputTest.java

License:Apache License

/**
 * Verifies that a asText() returns an empty string.
 * @throws Exception if the test fails//  ww w. j  av  a2s  . co  m
 */
@Test
public void asText() throws Exception {
    final String htmlContent = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'>\n"
            + "  <input type='number' name='foo' id='foo' value='123'>\n" + "</form></body></html>";

    final WebDriver driver = loadPage2(htmlContent);

    final WebElement input = driver.findElement(By.id("foo"));
    assertEquals("", input.getText());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlPasswordInputTest.java

License:Apache License

/**
 * Verifies that a asText() returns the value string.
 * @throws Exception if the test fails/*from  w w w. ja  va  2  s.  com*/
 */
@Test
public void asText() throws Exception {
    final String htmlContent = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'>\n"
            + "  <input type='password' name='foo' id='foo' value='bla'>\n" + "</form></body></html>";

    final WebDriver driver = loadPage2(htmlContent);

    final WebElement input = driver.findElement(By.id("foo"));
    assertEquals("", input.getText());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlTextArea2Test.java

License:Apache License

/**
 * @throws Exception if the test fails/*from  www.ja v  a2  s . com*/
 */
@Test
@Alerts(" foo \n bar\n test\n a <p>html snippet</p>")
public void asText() throws Exception {
    final String html = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'>\n"
            + "<textarea id='textArea1'> foo \n bar\r\n test\r a " + "<p>html snippet</p>\n" + "</textarea>\n"
            + "</form></body></html>";
    final WebDriver driver = loadPage2(html);
    final WebElement textArea = driver.findElement(By.id("textArea1"));
    assertEquals(getExpectedAlerts()[0], textArea.getText());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlTextArea2Test.java

License:Apache License

/**
 * @throws Exception if the test fails//  w  w w  . j ava  2s .  co  m
 */
@Test
@Alerts("")
public void asTextAndVisibility() throws Exception {
    final String html = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'>\n"
            + "<textarea id='textArea1' style='visibility:hidden'> foo \n bar " + "</textarea>\n"
            + "</form></body></html>";
    final WebDriver driver = loadPage2(html);
    final WebElement textArea = driver.findElement(By.id("textArea1"));
    assertEquals(getExpectedAlerts()[0], textArea.getText());
}