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:at.ac.tuwien.big.we14.lab2.tests.SeleniumTest.java

License:Open Source License

/**
 * answers the question with a specific answer type
 * /*from  ww w . j  av  a2s .c  om*/
 * @param question
 *            the question to answer (not null)
 * @param answerType
 *            the answer type
 */
private void answerQuestion(Question question, AnswerType answerType) {
    List<Choice> choices = answerType.createChoices(question.getWrongChoices(), question.getCorrectChoices());
    int totalChoices = question.getCorrectChoices().size() + question.getWrongChoices().size();
    List<Choice> selectedChoices = new ArrayList<>();
    for (int i = 0; i < totalChoices; i++) {
        WebElement choiceLabel = driver.findElement(By.id(ID_PREFIX_CHOICE_LABEL + i));
        WebElement checkbox = driver.findElement(By.id(choiceLabel.getAttribute("for")));
        for (Choice choice : choices) {
            if (choiceLabel.getText().contains(choice.getText())) {
                // click on a potentially invisible checkbox
                ((JavascriptExecutor) driver).executeScript("arguments[0].click()", checkbox);
                selectedChoices.add(choice);
                break;
            }
        }
    }

    if (selectedChoices.size() != choices.size()) {
        errorCollector.addError(
                new Exception(getTestInfoPrefix() + "Couldn't select the following choices: " + choices));
    }
    answers.add(new Answer(question, answerType, choices));
}

From source file:at.tugraz.ist.cucumber.SeleniumStepdefs.java

License:Open Source License

@When("^I change the language to \"([^\"]*)\"$")
public void I_change_the_language_to(String language) throws Throwable {
    WebElement select = driver().findElement(By.id("switchLanguage"));
    List<WebElement> options = select.findElements(By.tagName("option"));
    for (WebElement option : options) {
        if (option.getText().contains(language)) {
            option.click();/*from  www  .  j  a  v  a  2 s  . c  om*/
            blur(By.id("switchLanguage"));
            break;
        }
    }
    jqueryWait();
}

From source file:automation.HE.java

@After
public void tearDown() throws Exception {
    try {/*from   w w  w.j a v  a  2 s.  c  o  m*/
        //         result = driver.findElement(By.cssSelector(cssSelector)).getAttribute("innerHTML");
        result = "";
        WebElement table = driver.findElement(By.cssSelector(cssSelector));
        //         System.out.println("1" + table.getAttribute("innerHTML"));
        //         System.out.println("table:" + table.html());
        List<WebElement> rows = table.findElements(By.tagName("tr"));
        //         System.out.println("2");
        for (WebElement row : rows) {
            for (WebElement cell : row.findElements(By.tagName("td"))) {
                result += cell.getText().trim() + "\t";
            }
            result += "\n";
            //            System.out.println(result);
            //            System.out.println("------");
        }
        System.out.println(result);

    } catch (Exception e) {
        Logger.getLogger(BT.class.getName()).log(Level.SEVERE, null, e);
    } finally {

        super.store();

        driver.quit();
        String verificationErrorString = verificationErrors.toString();
        if (!"".equals(verificationErrorString)) {
            fail(verificationErrorString);
        }
    }
}

From source file:automation.PCCWGlobalcom.java

@After
public void tearDown() throws Exception {
    Thread.sleep(60 * 1000);//from ww w.j  av  a 2s  .co  m
    try {
        WebElement resultElement = driver.findElement(By.id("test_results"));
        List<WebElement> rows = resultElement.findElements(By.tagName("tr"));
        for (WebElement row : rows) {
            result += row.getText().trim() + "\n";

        }
        System.out.println(result);

        //         result = resultElement.getAttribute("innerHTML");
        //         result = result.replaceAll("[\u0000-\u0008]", "");
        //         result = result.replaceAll("[\u000B-\u001f]", "");
        //         result = replaceBrTag(result);
        //         result = removeTags(result);
        //         result = replaceHtmlString(result);
    } catch (Exception e) {
        Logger.getLogger(BT.class.getName()).log(Level.SEVERE, null, e);
    } finally {
        super.store();
        driver.quit();
        String verificationErrorString = verificationErrors.toString();
        if (!"".equals(verificationErrorString)) {
            fail(verificationErrorString);
        }
    }
}

From source file:be.rubus.web.jerry.validation.CombinedTest.java

License:Apache License

@Test
@RunAsClient//w ww.  j  a  v a2 s . c om
public void testCombined() throws Exception {
    driver.get(new URL(contextPath, "combined.xhtml").toString());

    WebElement element = driver.findElement(By.id("test:value"));
    assertThat(element.getAttribute("maxlength")).isNull();

    element = driver.findElement(By.id("test:valueLabel"));
    String text = element.getText();
    assertThat(text).isEqualTo("value");

    element = driver.findElement(By.id("test:required"));
    assertThat(element.getAttribute("maxlength")).isNull();

    element = driver.findElement(By.id("test:requiredLabel"));
    text = element.getText();
    assertThat(text).isEqualTo("required*");

    element = driver.findElement(By.id("test:maxLength"));
    assertThat(element.getAttribute("maxlength")).isEqualTo("14");

    element = driver.findElement(By.id("test:maxLengthLabel"));
    text = element.getText();
    assertThat(text).isEqualTo("max length");

    element = driver.findElement(By.id("test:combined"));
    assertThat(element.getAttribute("maxlength")).isEqualTo("14");

    element = driver.findElement(By.id("test:combinedLabel"));
    text = element.getText();
    assertThat(text).isEqualTo("combined*");

}

From source file:be.rubus.web.jerry.validation.CustomTest.java

License:Apache License

@Test
@RunAsClient/*from   www  .  ja  v a  2  s. com*/
public void testCustom() throws Exception {
    driver.get(new URL(contextPath, "custom.xhtml").toString());

    WebElement element = driver.findElement(By.id("test:zipCodeMaskLabel"));
    String text = element.getText();
    assertThat(text).isEqualTo("Zip code (mask)*");

    element = driver.findElement(By.id("test:zipCode"));
    assertThat(element.getAttribute("maxlength")).isEqualTo("4");

    element = driver.findElement(By.id("test:zipCodeMask"));

    element.sendKeys("azer");
    // Only numbers allowed in the mask
    assertThat(element.getAttribute("value")).isEqualTo("____");

    element.clear();
    element.sendKeys("12345");
    // Only 4 numbers allowed in the mask
    assertThat(element.getAttribute("value")).isEqualTo("1234");

}

From source file:be.rubus.web.jerry.validation.MaxSizeTest.java

License:Apache License

@Test
@RunAsClient// ww  w  .  ja v  a2 s . c o m
public void testMaxLength_TextArea() throws Exception {
    driver.get(new URL(contextPath, "maxSize_TextArea.xhtml").toString());

    WebElement element = driver.findElement(By.id("frm:description"));

    WebElement remaining = driver.findElement(By.id("frm:remaining"));
    assertThat(remaining.getText()).contains("10");

    element.sendKeys("abcde");
    assertThat(remaining.getText()).contains("5");

    element.sendKeys("abcdefghijk");
    assertThat(remaining.getText()).contains("0");

    assertThat(element.getAttribute("value")).isEqualTo("abcdeabcde");

}

From source file:be.rubus.web.jerry.validation.RequiredTest.java

License:Apache License

@Test
@RunAsClient/* w w  w.j av a  2 s  . com*/
public void testRequired() throws Exception {
    driver.get(new URL(contextPath, "required.xhtml").toString());

    WebElement element = driver.findElement(By.id("test:notRequiredLabel"));
    String text = element.getText();
    assertThat(text).isEqualTo("notRequired");

    element = driver.findElement(By.id("test:requiredLabel"));
    text = element.getText();
    assertThat(text).isEqualTo("required*");

    element = driver.findElement(By.id("test:sizeLabel"));
    text = element.getText();
    assertThat(text).isEqualTo("size");

    element = driver.findElement(By.id("test:specialLabel"));
    text = element.getText();
    assertThat(text).isEqualTo("special*");

}

From source file:be.rubus.web.testing.AbstractWidget.java

License:Apache License

public String getContentInAnyCase(WebElement element) {
    String result = element.getText();
    if (result == null || result.length() == 0) {
        result = element.getAttribute("textContent");
        if (result == null || result.length() == 0) {
            result = element.getAttribute("innerText");
        }//from   ww w.  j a v a 2s. c  o m
    }
    return result;
}

From source file:bi.meteorite.pages.LoginPage.java

License:Apache License

private Converter<WebElement, String> toStrings() {
    return new Converter<WebElement, String>() {
        public String convert(WebElement from) {
            return from.getText();
        }/*from w  ww. j  a v a  2s.  c o m*/
    };
}