Example usage for org.openqa.selenium WebElement getAttribute

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

Introduction

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

Prototype

String getAttribute(String name);

Source Link

Document

Get the value of the given attribute of the element.

Usage

From source file:com.fpt.datht.iap.AutoIAP.java

public static void getDataFromServer(String className) {
    int c = 0;//ww w.j  a  v  a2  s  .  c o m
    slots = new String[10];
    students = new LinkedList<>();
    new WebDriverWait(driver, 360).until(ExpectedConditions.titleIs("IAP"));
    driver.get("http://iap.fpt.edu.vn/activity");

    new WebDriverWait(driver, 360).until(ExpectedConditions.urlToBe("http://iap.fpt.edu.vn/activity/"));

    List<WebElement> els = driver.findElements(By.tagName("a"));
    System.out.println("Size a:" + els.size());
    for (WebElement e : els) {
        //  System.out.println(e.getText());
        if (e.getText().contains(className)) {

            slots[c] = e.getAttribute("href").replaceAll("http://iap.fpt.edu.vn/activity/index.php",
                    "http://iap.fpt.edu.vn/attendance/add.php");
            c++;
            count = c;
            // System.out.println(main);

        }
    }
    if (slots.length == 0)
        return;
    driver.get(slots[0]);

    try {
        new WebDriverWait(driver, 5)
                .until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//input[@type='submit']")));

    } catch (TimeoutException ex) {
        driver.get(slots[0].replaceAll("add.php", "edit.php"));

    }
    //Auto Check Slot 1
    if (autoCheckSlot1) {
        List<WebElement> elsInput = driver.findElements(By.xpath(".//input[@type='radio' and @value='1' ]"));
        autoCheckAll(elsInput);
    }

    //Wating for submit
    new WebDriverWait(driver, 5000)
            .until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//font[@color='green']")));
    driver.get(slots[0].replaceAll("add.php", "edit.php"));
    //GET All checked
    List<WebElement> elsInputChecked = driver
            .findElements(By.xpath(".//input[@type='radio' and @value='1' and @checked]"));

    System.out.println("Size input checked:" + elsInputChecked.size());

    elsInputChecked.stream().map((e) -> {
        Student student = new Student();
        student.name = e.getAttribute("name");
        return student;
    }).forEach(students::add);

}

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

License:Apache License

private boolean canReachWebUIs() {
    String url;//from www  .ja  va  2 s  .  co  m
    for (WebElement link : webURLLinks) {
        url = link.getAttribute("href");
        if (!Utils.canReachURL(url)) {
            logger.debug("cannot reach web ui: " + url);
            return false;
        }
    }
    return true;
}

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

License:Apache License

private void click(WebElement checkbox) {
    checkbox.click();/*from  w  w  w.j  ava2  s.com*/
    logger.debug("{} checkbox has been checked", checkbox.getAttribute("id"));
}

From source file:com.fullteaching.backend.e2e.FullTeachingTestE2E.java

License:Apache License

private void login(BrowserUser user, String userEmail, String userPass) {
    user.getDriver().findElement(By.id("download-button")).click();

    // Find form elements (login modal is already opened)
    WebElement userNameField = user.getDriver().findElement(By.id("email"));
    WebElement userPassField = user.getDriver().findElement(By.id("password"));

    // Fill input fields
    userNameField.sendKeys(userEmail);/* w ww  .j a  v a2  s . co  m*/
    userPassField.sendKeys(userPass);

    // Ensure fields contain what has been entered
    Assert.assertEquals(userNameField.getAttribute("value"), userEmail);
    Assert.assertEquals(userPassField.getAttribute("value"), userPass);

    user.getDriver().findElement(By.id("log-in-btn")).click();
}

From source file:com.fullteaching.backend.e2e.FullTeachingTestE2ESleep.java

License:Apache License

private void login(BrowserUser user, String userEmail, String userPass) {
    user.getDriver().findElement(By.id("download-button")).click();

    // Find form elements (login modal is already opened)
    WebElement userNameField = user.getDriver().findElement(By.id("email"));
    WebElement userPassField = user.getDriver().findElement(By.id("password"));

    // Fill input fields
    userNameField.sendKeys(userEmail);/*from www.  j a v a  2  s.  com*/

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    userPassField.sendKeys(userPass);

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    // Ensure fields contain what has been entered
    Assert.assertEquals(userNameField.getAttribute("value"), userEmail);
    Assert.assertEquals(userPassField.getAttribute("value"), userPass);

    user.getDriver().findElement(By.id("log-in-btn")).click();
}

From source file:com.galenframework.page.selenium.WebPageElement.java

License:Apache License

@Override
public String getText() {
    WebElement webElement = getWebElement();
    if ("input".equals(webElement.getTagName().toLowerCase())) {
        String value = webElement.getAttribute("value");
        if (value == null) {
            value = "";
        }/*from w  w  w .  ja  va2 s  . c  o m*/

        return value;
    } else
        return getWebElement().getText().trim();
}

From source file:com.gargoylesoftware.htmlunit.activex.javascript.msxml.XMLSerializerTest.java

License:Apache License

/**
 * @throws Exception if the test fails/*from  w ww  .j  a  v  a 2  s. com*/
 */
@Test
@Alerts(DEFAULT = "no ActiveX", IE = {})
public void test() throws Exception {
    final String expectedString = getExpectedAlerts().length != 0 ? ""
            : "<note>13109<to>Tove</to>13109<from>Jani</from>13109<body>Do32not32forget32me32this32weekend!</body>"
                    + "13109<outer>131099<inner>Some32Value</inner></outer>1310</note>1310";

    final String serializationText = "<note> " + "<to>Tove</to> \\n" + "<from>Jani</from> \\n "
            + "<body>Do not forget me this weekend!</body> " + "<outer>\\n " + "  <inner>Some Value</inner>"
            + "</outer> " + "</note>";

    final WebDriver driver = loadPageWithAlerts2(constructPageContent(serializationText));
    final WebElement textArea = driver.findElement(By.id("myTextArea"));
    assertEquals(expectedString, textArea.getAttribute("value"));
}

From source file:com.gargoylesoftware.htmlunit.activex.javascript.msxml.XMLSerializerTest.java

License:Apache License

/**
 * @throws Exception if the test fails//from   ww  w .ja  v a2 s .co  m
 */
@Test
@Alerts(DEFAULT = "no ActiveX", IE = {})
public void comment() throws Exception {
    final String expectedString = getExpectedAlerts().length != 0 ? "" : "<a><!--32abc32--></a>1310";

    final String serializationText = "<a><!-- abc --></a>";
    final WebDriver driver = loadPageWithAlerts2(constructPageContent(serializationText));
    final WebElement textArea = driver.findElement(By.id("myTextArea"));
    assertEquals(expectedString, textArea.getAttribute("value"));
}

From source file:com.gargoylesoftware.htmlunit.activex.javascript.msxml.XMLSerializerTest.java

License:Apache License

/**
 * @throws Exception if the test fails//  www  . j a  v  a 2  s.com
 */
@Test
@Alerts(DEFAULT = "no ActiveX", IE = {})
public void xmlEntities() throws Exception {
    final String expectedString = getExpectedAlerts().length != 0 ? "" : "<a>&lt;&gt;&amp;</a>1310";
    final String serializationText = "<a>&lt;&gt;&amp;</a>";
    final WebDriver driver = loadPageWithAlerts2(constructPageContent(serializationText));
    final WebElement textArea = driver.findElement(By.id("myTextArea"));
    assertEquals(expectedString, textArea.getAttribute("value"));
}

From source file:com.gargoylesoftware.htmlunit.activex.javascript.msxml.XMLSerializerTest.java

License:Apache License

/**
 * @throws Exception if the test fails/*from  w  w w.j  a  va  2s .  co  m*/
 */
@Test
@Alerts(DEFAULT = "no ActiveX", IE = {})
@NotYetImplemented(IE)
// so far we are not able to add the XML header
public void nameSpaces() throws Exception {
    final String expectedString = getExpectedAlerts().length != 0 ? ""
            : "<?xml32version=\"1.0\"?>1310<xsl:stylesheet32version=\"1.0\"32"
                    + "xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">13109<xsl:template32match=\"/\">131099<html>"
                    + "1310999<body>1310999</body>131099</html>13109</xsl:template>1310</xsl:stylesheet>1310";

    final String serializationText = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\\n"
            + "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\\n"
            + "  <xsl:template match=\"/\">\\n" + "  <html>\\n" + "    <body>\\n" + "    </body>\\n"
            + "  </html>\\n" + "  </xsl:template>\\n" + "</xsl:stylesheet>";

    final WebDriver driver = loadPageWithAlerts2(constructPageContent(serializationText));
    final WebElement textArea = driver.findElement(By.id("myTextArea"));
    assertEquals(expectedString, textArea.getAttribute("value"));
}