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.autocognite.selenium.lib.SeleniumWebUiDriver.java

License:Apache License

public String getAttribute(WebElement wdElement, String attr) throws Exception {
    return wdElement.getAttribute(attr);
}

From source file:com.bc.opec.webtests.TestUserInfo.java

License:Open Source License

@Test
public void testThatUserInfoBalloonIsShown() throws Exception {
    WebElement webElement = driver.findElement(By.xpath("//*/div[@aria-describedby='user-info-balloon']"));
    assertNotNull(webElement);//from w  w  w . j ava2s  .  co  m
    if (webElement.getAttribute("aria-describedby").equals("user-info-balloon")) {
        assertEquals("none", webElement.getCssValue("display").toLowerCase());

        final WebElement element = driver.findElement(By.id("userInfoToggleBtn"));
        Actions actions = new Actions(driver);
        actions.moveToElement(element).click().perform();

        assertEquals("block", webElement.getCssValue("display").toLowerCase());
    }
}

From source file:com.bc.opec.webtests.WebTestBase.java

License:Open Source License

public void closePopups() {
    Assert.assertTrue(driver.getTitle().startsWith("OPEC"));
    for (WebElement e : driver.findElements(By.tagName("Button"))) {
        if (e.getAttribute("title").equals("Close")) {
            e.click();/*from www . j a  v a2  s .  c  o m*/
            break;
        }
    }
    for (WebElement e : driver.findElements(By.tagName("Button"))) {
        if (e.getText().equals("No")) {
            e.click();
            break;
        }
    }
    driver.findElement(
            By.xpath("//*/div[@aria-describedby='gisportal-layerSelection']/div/div/button[@title='close']"))
            .click();
}

From source file:com.bna.ezrxlookup.ui.web.EZRxBusinessTests.java

License:Apache License

@Test
public void testEZRxLookupResultPageNoNegativeNoRecalls() throws Exception {
    try {//from   w w  w.  j  av a  2 s .c  o m
        driver.get(baseUrl + "/EZRxLookup/");
        driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).clear();
        driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).sendKeys("");
        driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).clear();
        driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).sendKeys("51439-007-02");
        driver.findElement(By.id("j_idt5:j_idt18:search")).click();
        for (int second = 0;; second++) {
            if (second >= 10)
                fail("timeout");
            try {
                if (isElementPresent(By.cssSelector("label")))
                    break;
            } catch (Exception e) {
            }
            Thread.sleep(1000);
        }
        Thread.sleep(3000);
        assertEquals("ACNE CLEARNING TREATMENT FACE",
                driver.findElement(By.id("j_idt5:j_idt19:cmdBName")).getText());

        WebElement element = driver.findElement(By.id("j_idt5:j_idt19:j_idt28"));
        String path = element.getAttribute("src");
        assert (path.contains("green"));

    } catch (Error e) {
        verificationErrors.append(e);

    }
}

From source file:com.bna.ezrxlookup.ui.web.EZRxBusinessTests.java

License:Apache License

@Test
public void testEZRxLookupResultPageNegativeEventsNoRecalls() throws Exception {
    try {//from   w  w w  .  ja  v  a 2s. co  m
        driver.get(baseUrl + "/EZRxLookup/");
        driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).clear();
        driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).sendKeys("");
        driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).clear();
        driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).sendKeys("53746-078-01");
        driver.findElement(By.id("j_idt5:j_idt18:search")).click();
        for (int second = 0;; second++) {
            if (second >= 10)
                fail("timeout");
            try {
                if (isElementPresent(By.cssSelector("label")))
                    break;
            } catch (Exception e) {
            }
            Thread.sleep(1000);
        }
        Thread.sleep(3000);
        assertEquals("ESTERIFIED ESTROGENS AND METHYLTESTOSTERONE",
                driver.findElement(By.id("j_idt5:j_idt19:cmdBName")).getText());

        WebElement element = driver.findElement(By.id("j_idt5:j_idt19:j_idt28"));
        String path = element.getAttribute("src");
        assert (path.contains("yellow"));
    } catch (Error e) {
        verificationErrors.append(e);

    }
}

From source file:com.bna.ezrxlookup.ui.web.EZRxBusinessTests.java

License:Apache License

@Test
public void testEZRxLookupResultPageRecallsFound() throws Exception {
    try {/*from  w  ww. j  ava 2 s  .  c  o m*/
        driver.get(baseUrl + "/EZRxLookup/");
        driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).clear();
        driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).sendKeys("");
        driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).clear();
        driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).sendKeys("43598-209-53");
        driver.findElement(By.id("j_idt5:j_idt18:search")).click();
        for (int second = 0;; second++) {
            if (second >= 10)
                fail("timeout");
            try {
                if (isElementPresent(By.cssSelector("label")))
                    break;
            } catch (Exception e) {
            }
            Thread.sleep(1000);
        }
        Thread.sleep(3000);
        assertEquals("AMOXICILLIN", driver.findElement(By.id("j_idt5:j_idt19:cmdBName")).getText());
        WebElement element = driver.findElement(By.id("j_idt5:j_idt19:j_idt28"));
        String path = element.getAttribute("src");
        assert (path.contains("red"));
    } catch (Error e) {
        verificationErrors.append(e);

    }
}

From source file:com.cengage.mindtap.keywords.MasterPageActions.java

public void clickBookModifyOption(String searchTerm, String option, String role) {
    int optionNumber = 0;
    int optionsCount = 0;
    int i = 0;/*from   w w w  . j a  v  a  2 s . com*/
    optionNumber = findoptionNumber(option, role);

    List<WebElement> masterBook_list = driver
            .findElements(By.xpath("//li[contains(@class, 'item  master admin_models_master')]"));
    for (WebElement masterBook : masterBook_list) {
        System.out.println("In masterBook ");
        //if (masterBook.findElement(By.xpath("(//div/div[@class='listText']/a)[2]")).getText().equals(searchTerm)  || masterBook.findElement(By.xpath("//div/div[@class='listText']/a")).getText().equals(searchTerm)) {
        if (masterBook.findElement(By.xpath("//div/div[@class='listText']/a")).getText().equals(searchTerm)) {
            System.out.println("In IF ");
            String bookClassName = masterBook.getAttribute("class");
            System.out.println("optionCount : " + optionNumber);
            executeJavascript("document.getElementsByClassName('" + bookClassName
                    + "')[0].getElementsByTagName('a')[" + optionNumber + "].style.display = 'block';");
            wait.hardWait(2);
            for (WebElement option1 : elements("masterBookControlOptions_list", option)) {
                try {
                    System.out.println("optionCount : " + optionNumber);
                    System.out.println(option1.getAttribute("alt"));
                    System.out.println(option);
                    if (option1.isDisplayed() && option1.getAttribute("alt").equals(option)) {
                        System.out.println("optionCount : " + optionNumber);
                        executeJavascript("document.getElementsByClassName('" + bookClassName
                                + "')[0].getElementsByTagName('a')[" + optionNumber
                                + "].style.display = 'block';");
                        hover(option1);
                        clickOnElementUsingActionBuilder(option1);

                        if (option.equals("Delete")) {
                            handleAlert();
                            wait.hardWait(20);
                        }
                        break;
                    }
                } catch (ElementNotFoundException e) {
                    System.out.println("Options are not available to Click");
                }
            }
            break;
        }
    }
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

@Override
public void select(String selectLocator, String optionLocator) {
    Select select = new Select(findElement(selectLocator));
    List<WebElement> options = select.getOptions();
    log.debug("options found " + options.size() + " elements");
    String[] locator = optionLocator.split("=");
    log.debug("Locator has " + locator.length + " elements");
    String find;//from ww  w.j  a v a2s.  c o  m
    if (locator.length > 1) {
        find = locator[1];
    } else {
        find = locator[0];
    }
    log.debug(" find is " + find);
    if (locator[0].contains(VALUE)) {
        log.debug("checking value");
        for (WebElement we : options) {
            log.debug("Printing found options: " + we.getAttribute(VALUE));
            if (we.getAttribute(VALUE).equals(find)) {
                we.click();
                break;
            }
        }
    } else if (locator[0].contains("id")) {
        log.debug("checking id");
        for (WebElement we : options) {
            log.debug("Printing found options: " + we.getAttribute("id"));
            if (we.getAttribute("id").equals(find)) {
                we.click();
                break;
            }
        }
    } else if (locator[0].contains("index")) {
        log.debug("checking index");
        for (WebElement we : options) {
            log.debug("Printing found options: " + we.getAttribute("index"));
            if (we.getAttribute("index").equals(find)) {
                we.click();
                break;
            }
        }
    } else {
        boolean flag = false;
        log.debug("checking text or label, default option");
        for (WebElement we : options) {
            log.debug("Printing found options: " + we.getText());
            if (we.getText().equals(find)) {
                we.click();
                flag = true;
                break;
            }
        }
        if (flag == false) {
            click(optionLocator);
        }
    }
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

@Override
public boolean isSelectOptionEnable(String selectLocator, String optionLocator) {
    Select select = new Select(findElement(selectLocator));
    List<WebElement> options = select.getOptions();
    log.debug("options found " + options.size() + " elements");
    String[] locator = optionLocator.split("=");
    log.debug("Locator has " + locator.length + " elements");
    String find;/*from w ww .  j a va  2 s  .  c  om*/
    if (locator.length > 1) {
        find = locator[1];
    } else {
        find = locator[0];
    }
    log.debug(" find is " + find);
    if (locator[0].contains(VALUE)) {
        log.debug("checking value");
        for (WebElement we : options) {
            log.debug("Printing found options: " + we.getAttribute(VALUE));
            if (we.getAttribute(VALUE).equals(find)) {
                return we.isEnabled();
            }
        }
    } else if (locator[0].contains("id")) {
        log.debug("checking id");
        for (WebElement we : options) {
            log.debug("Printing found options: " + we.getAttribute("id"));
            if (we.getAttribute("id").equals(find)) {
                return we.isEnabled();
            }
        }
    } else if (locator[0].contains("index")) {
        log.debug("checking index");
        for (WebElement we : options) {
            log.debug("Printing found options: " + we.getAttribute("index"));
            if (we.getAttribute("index").equals(find)) {
                return we.isEnabled();
            }
        }
    } else {
        log.debug("checking text or label, default option");
        for (WebElement we : options) {
            log.debug("Printing found options: " + we.getText());
            if (we.getText().equals(find)) {
                return we.isEnabled();
            }
        }
    }
    return false;
}

From source file:com.cisco.dbds.utils.primewidgets.pagefactory.primePageFactory.java

License:Open Source License

/**
 * Gets the mainmenu sel.//  ww  w  .  j  a  va2s .  c o  m
 *
 * @param mname the mname
 * @return the mainmenu sel
 */
public WebElement getMAINMENU_SEL(String mname) {
    WebElement dupli = null;
    for (WebElement elem : WES_PRIME_SYSTEM_ADMINISTRATION_PLANE_CSS_SEL) {
        String attr = elem.getAttribute("title");
        if (attr.equals(mname)) {
            dupli = elem;
        }
    }
    return dupli;
}