Example usage for org.openqa.selenium By tagName

List of usage examples for org.openqa.selenium By tagName

Introduction

In this page you can find the example usage for org.openqa.selenium By tagName.

Prototype

public static By tagName(String tagName) 

Source Link

Usage

From source file:com.gorillalogic.agents.html.automators.WebElementAutomator.java

License:Open Source License

public WebElement getElement() {
    if (element != null) {
        return element;
    }//from  w w w .  ja v a  2s .c o m

    String xpath = getLocatorExpr();
    try {
        List<WebElement> elements = driver.findElements(By.xpath(xpath));
        if (elements.size() == 0) {
            throw new IllegalArgumentException(
                    "Unable to find html element with monkeyID '" + this.monkeyId + "'");
        }
        int monkeyIndex = 0;

        if (getMonkeyOrdinal() != null) {
            String monkeyOrdinal = getMonkeyOrdinal().get(1);
            monkeyIndex = Integer.parseInt(monkeyOrdinal) - 1;

            if (Integer.parseInt(monkeyOrdinal) > elements.size())
                throw new IllegalArgumentException(
                        "Unable to find html element with monkeyID '" + this.monkeyId + "'");
        }

        driver.switchTo().defaultContent();
        element = elements.get(monkeyIndex);
    } catch (NoSuchElementException e1) {
        // OK
    }
    if (element != null) {
        return element;
    }

    List<WebElement> frameset = driver.findElements(By.tagName("iframe"));
    for (WebElement framename : frameset) {
        try {
            List<WebElement> elements = driver.findElements(By.xpath(xpath));
            int monkeyIndex = 0;

            if (getMonkeyOrdinal() != null) {
                String monkeyOrdinal = getMonkeyOrdinal().get(1);
                monkeyIndex = Integer.parseInt(monkeyOrdinal) - 1;

                if (Integer.parseInt(monkeyOrdinal) > elements.size())
                    throw new IllegalArgumentException(
                            "Unable to find button with monkeyID '" + this.monkeyId + "'");
            }

            driver.switchTo().defaultContent();
            driver.switchTo().frame(framename);
            element = elements.get(monkeyIndex);
            break;
        } catch (NoSuchElementException e) {

        }
    }
    if (element == null) {
        throw new IllegalArgumentException(
                "Unable to find " + getComponentType() + " with monkeyId '" + monkeyId + "'");
    }
    return element;
}

From source file:com.guidewire.pstesting.policycenter.submission.gbpa.GBDriverRolesPanel.java

protected void setAccidentViolationLevel(String rowText, int columnIndex, String listItem) {
    if (listItem != null) {
        WebElement rowElement = getController().findRow(accidentsViolationsSummaryTableLocator, rowText);
        WebElement cellElement = rowElement.findElements(By.tagName("td")).get(columnIndex);
        By listLocator = By.className("x-list-plain");
        getController().clickAndWait(cellElement, listLocator).type(listItem).sleep(250).pressEnter()
                .sleep(250);//from  www. ja v a 2  s  . c om
    }
}

From source file:com.guidewire.pstesting.policycenter.submission.pa.DriverRolesPanel.java

protected void setAccidentViolationLevel(String rowText, int columnIndex, String listItem) {
    if (listItem != null) {
        WebElement rowElement = getController().findRow(accidentsViolationsSummaryTableLocator, rowText);
        WebElement cellElement = rowElement.findElements(By.tagName("td")).get(columnIndex);
        //Cell changes to input once list is invoked - use name attribute for each
        By cellInputLocator = By.name("c" + columnIndex);
        By listLocator = By.className("x-list-plain");
        try {// w  w w  .  ja v a2  s. c  o  m
            getController().clickRightEdgeAndWait(cellElement, listLocator);
        } catch (Exception e) {
            getController().clickAndWaitFluently(cellElement, listLocator);
        }
        getController().setTextAndTab(cellInputLocator, listItem);
    }
}

From source file:com.gumtreescraper.scraper.GumtreeScraper.java

public boolean login() {
    openSite(LOGIN_URL);//  www  .  j  a  va 2 s .  co m
    webDriver.findElement(By.id("login-email")).sendKeys(username);
    webDriver.findElement(By.id("login-password")).sendKeys(password);
    webDriver.findElement(By.className("login-form-submit")).findElement(By.tagName("button")).click();

    //        waitForSeconds(10);

    try {
        // if found then return true, otherwise return false
        (new WebDriverWait(this.webDriver, SPECIAL_TIMEOUT))
                .until(ExpectedConditions.presenceOfElementLocated(By.className("item-sign-out")));
        //            webDriver.findElement(By.className("item-sign-out")); 
    } catch (Exception ex) {
        System.out.println(ex);
        return false;
    }

    return true;
}

From source file:com.hack23.cia.systemintegrationtest.UserPageVisit.java

License:Apache License

/**
 * Gets the iframes html body as text./* ww  w.j a v a 2 s . c  om*/
 *
 * @return the iframes html body as text
 */
public String getIframesHtmlBodyAsText() {
    final StringBuilder stringBuilder = new StringBuilder();
    final List<WebElement> ele = driver.findElements(By.tagName("iframe"));
    for (final WebElement el : ele) {
        driver.switchTo().frame(el);

        stringBuilder.append(driver.findElement(By.tagName("body")).getText());
        driver.switchTo().defaultContent();
    }
    return stringBuilder.toString();
}

From source file:com.hack23.cia.systemintegrationtest.UserPageVisit.java

License:Apache License

/**
 * Gets the html body as text.//from  w w w .  j  a v a  2 s.c o  m
 *
 * @return the html body as text
 */
private String getHtmlBodyAsText() {
    return driver.findElement(By.tagName("body")).getText();
}

From source file:com.hack23.cia.systemintegrationtest.UserPageVisit.java

License:Apache License

/**
 * Logout user.//from ww w .  ja va 2 s. c om
 *
 * @throws Exception
 *             the exception
 */
public void logoutUser() throws Exception {

    final WebElement logoutButton = findButton("Logout");
    assertNotNull("Expect to find a Logout Button", logoutButton);

    final Cookie cookie = driver.manage().getCookieNamed("JSESSIONID");
    final String sessionId = cookie.getValue();

    performClickAction(logoutButton);

    final WebElement body = driver.findElement(By.tagName("body"));
    body.sendKeys(Keys.ESCAPE);

    waitForBrowser(1000);
    driver.navigate().refresh();
    waitForBrowser(2000);

    final Cookie newCookie = driver.manage().getCookieNamed("JSESSIONID");

    final String newSessionId = newCookie.getValue();

    assertNotEquals(sessionId, newSessionId);

    final String url = systemTestTargetUrl + "#!" + CommonsViews.MAIN_VIEW_NAME;

    assertEquals(browser, url, driver.getCurrentUrl());

}

From source file:com.hotwire.selenium.angular.AngularHotelResultsPage.java

License:Open Source License

public SearchSolution bookFirstSolution() {
    WebElement element = resultsList.get(0).findElement(By.tagName("a"));
    SearchSolution solution = new SearchSolution();
    solution.setHotelName(element.findElement(By.cssSelector(" h2[data-bdd='title']")).getText().trim());
    solution.setPrice(element.findElement(By.cssSelector("div[data-bdd='displayPrice']")).getText().trim());
    solution.setRating(//from  w  ww  .j a v  a2s  . c  o  m
            element.findElement(By.cssSelector("img[data-bdd='starRating']")).getAttribute("data-star"));
    element.click();
    return solution;
}

From source file:com.hotwire.selenium.bex.hotel.search.HotelSearchPage.java

License:Open Source License

public void selectProxDates() {
    if (startDateField != null) {

        startDateField.click();/*from   w  w w .  jav a  2s  .  com*/
        WebElement dateWidget = getWebDriver().findElement(By.xpath("//ul[@class='cal-dates']"));
        List<WebElement> options = dateWidget.findElements(By.tagName("li"));
        for (WebElement opt : options) {
            try {
                opt.findElement(By.tagName("a"));
                opt.click();
                break;
            } catch (NoSuchElementException e) {
                LOGGER.info("date was not clickable");
            }
        }
    }
}

From source file:com.hotwire.selenium.bex.hotel.search.HotelSearchPage.java

License:Open Source License

public void selectFarDates() {
    if (startDateField != null) {

        startDateField.click();//from w w w .j  av  a 2 s .co  m
        getWebDriver().findElement(By.xpath("//button[@class='btn-paging btn-secondary next']")).click();
        WebElement dateWidget = getWebDriver().findElement(By.xpath("//ul[@class='cal-dates']"));
        List<WebElement> options = dateWidget.findElements(By.tagName("li"));
        for (WebElement opt : options) {
            try {
                opt.findElement(By.tagName("a"));
                opt.click();
                break;
            } catch (NoSuchElementException e) {
                LOGGER.info("date not clickable");
            }
        }
    }
}