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.ecofactor.qa.automation.newapp.page.impl.TstatControlUIPageImpl.java

License:Open Source License

/**
 * Opacity value.//from www.  ja  v  a2 s  . com
 * @param containerClassName the container class name
 */
private void opacityValue(String containerClassName) {

    isDisplayed(getDriver(), By.className(containerClassName), SHORT_TIMEOUT);
    WebElement thermostatControlContainer = getElement(getDriver(), By.className(containerClassName),
            SHORT_TIMEOUT);
    List<WebElement> buttonElements = getElementsBySubElement(getDriver(), thermostatControlContainer,
            By.tagName(TAG_INPUT), SHORT_TIMEOUT);
    int loop = 0;
    for (WebElement element : buttonElements) {
        String classname = element.getAttribute("className");
        if (element.getAttribute(ATTR_TYPE).endsWith("button") && classname != null && !classname.isEmpty()) {
            String classNameSplit = classname.contains(SELECTED) ? classname.split(" ")[0] : classname;
            JavascriptExecutor js = (JavascriptExecutor) getDriver();
            Object val = js.executeScript(
                    "return window.document.defaultView.getComputedStyle(window.document.getElementsByClassName('"
                            + classNameSplit + "')['" + loop + "']).getPropertyValue('background-color');");
            loop++;
            String opacity = val.toString();
            opacity = opacity.substring(opacity.lastIndexOf(",") + 1);
            opacity = opacity.substring(0, opacity.indexOf(")"));

            Double currentOpacity = Double.valueOf(opacity.toString().trim());
            if (classname.contains(SELECTED)) {
                final Double opacityValueSelected = 0.5;
                LogUtil.setLogString(
                        "Verify the opacity for '" + element.getAttribute(ATTR_VALUE) + "' (Button selected)",
                        true, CustomLogLevel.LOW);
                LogUtil.setLogString("Expected opacity in between 0.48 and 0.0", true, CustomLogLevel.HIGH);
                LogUtil.setLogString("The opacity in UI is :" + currentOpacity, true, CustomLogLevel.HIGH);
                Assert.assertTrue(
                        (opacityValueSelected > currentOpacity && currentOpacity >= 0.0)
                                || opacityValueSelected.equals(currentOpacity),
                        "Opacity value for buttons differ.");
            } else {
                LogUtil.setLogString("Verify the opacity for '" + element.getAttribute(ATTR_VALUE)
                        + "' button, (Button Not selected)", true);
                LogUtil.setLogString("Expected opacity in between 0.0 and 0.40", true, CustomLogLevel.HIGH);
                LogUtil.setLogString("The opacity in UI is :" + currentOpacity, true, CustomLogLevel.HIGH);
                final Double opacityValueSelected = 0.40;
                Assert.assertTrue(
                        (opacityValueSelected > currentOpacity && currentOpacity >= 0.0)
                                || currentOpacity.equals(opacityValueSelected),
                        "Opacity value for buttons differ.");
            }

        }

    }
}

From source file:com.ecofactor.qa.automation.newapp.page.impl.TstatControlUIPageImpl.java

License:Open Source License

/**
 * Gets the rgb./*from  w w w  . ja  v  a  2 s  .  c o  m*/
 * @param containerClassName the container class name
 * @param mode the mode
 * @return the rgb
 */
private String getRgb(String containerClassName, String mode) {

    isDisplayed(getDriver(), By.className(containerClassName), SHORT_TIMEOUT);
    WebElement thermostatControlContainer = getElement(getDriver(), By.className(containerClassName),
            SHORT_TIMEOUT);
    List<WebElement> buttonElements = getElementsBySubElement(getDriver(), thermostatControlContainer,
            By.tagName(TAG_INPUT), SHORT_TIMEOUT);
    int loop = 0;
    String colorValue = null;
    for (WebElement element : buttonElements) {
        String classname = element.getAttribute("className");
        if (element.getAttribute(ATTR_TYPE).endsWith("button") && classname != null && !classname.isEmpty()) {
            String classNameSplit = classname.contains(SELECTED) ? classname.split(" ")[0] : classname;
            JavascriptExecutor js = (JavascriptExecutor) getDriver();
            Object val = js.executeScript(
                    "return window.document.defaultView.getComputedStyle(window.document.getElementsByClassName('"
                            + classNameSplit + "')['" + loop + "']).getPropertyValue('background-color');");
            loop++;
            String rgbValue = val.toString();
            rgbValue = rgbValue.substring(5, 16);
            if (classname.contains(SELECTED) && mode.equalsIgnoreCase("cool")) {
                LogUtil.setLogString(
                        "Verify the Color for '" + element.getAttribute(ATTR_VALUE) + "' (Button selected)",
                        true, CustomLogLevel.LOW);
                LogUtil.setLogString("Expected Color " + COOL_MODE_COLOR, true, CustomLogLevel.MEDIUM);
                LogUtil.setLogString("The Color in UI is :" + rgbValue, true, CustomLogLevel.MEDIUM);
                colorValue = rgbValue;
            } else if (classname.contains(SELECTED) && mode.equalsIgnoreCase("heat")) {
                LogUtil.setLogString(
                        "Verify the Color for '" + element.getAttribute(ATTR_VALUE) + "' (Button selected)",
                        true, CustomLogLevel.LOW);
                LogUtil.setLogString("Expected Color " + HEAT_MODE_COLOR, true, CustomLogLevel.MEDIUM);
                LogUtil.setLogString("The Color in UI is :" + rgbValue, true, CustomLogLevel.MEDIUM);
                colorValue = rgbValue;
            }
        }
    }
    return colorValue;

}

From source file:com.ecofactor.qa.automation.qtc.page.TaskPageImpl.java

License:Open Source License

/**
 * Click next2./*from   w ww  .j  av  a2s . c o m*/
 * @see com.ecofactor.qa.automation.qtc.page.TaskPage#clickNext2()
 */
public void clickNext2() {

    DriverConfig.setLogString("Click Next", true);

    smallWait();

    WebElement taskContainer = DriverConfig.getDriver().findElement(By.id("taskConfigContainer"));

    List<WebElement> omput = taskContainer.findElements(By.tagName("input"));
    for (WebElement webElement : omput) {
        if (webElement.getAttribute(ATTR_VALUE).equalsIgnoreCase(taskConfig.get(NEXT))) {
            webElement.click();
            break;
        }
    }
}

From source file:com.ecofactor.qa.automation.util.HttpsUtil.java

License:Open Source License

/**
 * Gets the./*from   w w w .  j a va 2s .co  m*/
 * @param url the url
 * @return the https response
 */
public static String get(String url, Map<String, String> params, int expectedStatus) {

    String content = null;
    HttpGet request = new HttpGet(url);
    URIBuilder builder = new URIBuilder(request.getURI());

    if (params != null) {
        Set<String> keys = params.keySet();
        for (String key : keys) {
            builder.addParameter(key, params.get(key));
        }
    }

    try {
        request.setURI(builder.build());
        DriverConfig.setLogString("URL " + request.getURI().toString(), true);
        driver.navigate().to(request.getURI().toString());
        tinyWait();
        content = driver.findElement(By.tagName("Body")).getText();
        DriverConfig.setLogString("Content: " + content, true);
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
    } finally {
        request.releaseConnection();
    }

    return content;
}

From source file:com.ecofactor.qa.automation.util.mail.Gmail.java

License:Open Source License

/**
 * Gets the changed password./*from   w w w. j  av  a  2 s  . c  om*/
 * @param url the url
 * @param emailUserName the email user name
 * @param emailPassword the email password
 * @param subject the subject
 * @param boldIndex the bold index
 * @param pwdIndex the pwd index
 * @return the changed password
 */
public String getChangedPassword(String url, String emailUserName, String emailPassword, String subject,
        int boldIndex, int pwdIndex) {

    WebDriver driver = DriverConfig.getDriver();
    if (DriverConfig.getDriver() == null) {
        driverConfig.loadDriver();
        driver = DriverConfig.getDriver();
    }

    String tempPassword = null;

    largeWait();
    DriverConfig.setLogString("Load Email portal URL at change password", true);
    driver.navigate().to(url + "" + emailUserName);
    largeWait();

    boolean session = isDisplayedById(driver, "Passwd", MEDIUM_TIMEOUT);
    if (session) {
        DriverConfig.setLogString(
                "Enter username and password for Email(" + emailUserName + "/" + emailPassword + ")", true);
        driver.findElement(By.id("Email")).sendKeys(emailUserName);
        driver.findElement(By.id("Passwd")).sendKeys(emailPassword);

        mediumWait();
        WebElement signInButtonElement = driver.findElement(By.id("signIn"));
        DriverConfig.setLogString("click Sign In button", true);
        signInButtonElement.click();
        largeWait();
        boolean button = isDisplayedById(driver, "no-button", MEDIUM_TIMEOUT);
        if (button) {
            WebElement buttonElement = driver.findElement(By.id("no-button"));
            buttonElement.click();
            mediumWait();
        }
    }

    isDisplayedByCSS(driver, ".aio.UKr6le", MEDIUM_TIMEOUT);
    DriverConfig.setLogString("Click Inbox.", true);
    WebElement inboxElement = DriverConfig.getDriver().findElement(By.partialLinkText("Inbox"));
    inboxElement.click();
    largeWait();

    DriverConfig.setLogString("Click Subject of Email.", true);
    WebElement webElement = driver.findElement(By.cssSelector(".ae4.UI.UJ"));
    List<WebElement> tagElement = webElement.findElements(By.tagName(TAG_BOLD));
    WebElement firstElement = tagElement.get(0);
    if (firstElement != null && firstElement.isDisplayed()
            && firstElement.getText().equalsIgnoreCase(subject)) {
        firstElement.click();
        largeWait();
    }

    DriverConfig.setLogString("Get temporary Password/activation link from Email.", true);
    if (boldIndex == 1) {
        WebElement divBodyElement = driver.findElement(By.xpath("//*[contains(@class,'adO')]"));
        if (pwdIndex == 1) {
            WebElement pwdElement = divBodyElement.findElements(By.tagName(TAG_STRONG)).get(0);
            tempPassword = pwdElement.getText();
            DriverConfig.setLogString("Temporary password got from email " + tempPassword, true);
        } else {
            WebElement pwdElement = divBodyElement.findElements(By.tagName(TAG_ANCHOR)).get(0);
            tempPassword = pwdElement.getText();
            DriverConfig.setLogString("Activation link got from email " + tempPassword, true);
        }
    } else if (boldIndex == 0) {
        DriverConfig.setLogString("Header Tag", true);
        WebElement divBodyElement = driver.findElement(By.className("gs"));
        List<WebElement> headerElement = divBodyElement.findElements(By.tagName("strong"));
        for (WebElement webelement : headerElement) {
            if (webelement.isDisplayed()) {
                tempPassword = webelement.getText();
                DriverConfig.setLogString("Temporary password got from email " + tempPassword, true);
            }
        }
    }
    mediumWait();

    deleteFirstMail(driver);

    DriverConfig.setLogString("Click user for Signout option", true);
    boolean value = isDisplayedById(DriverConfig.getDriver(), "gbgs4dn", MEDIUM_TIMEOUT);
    DriverConfig.setLogString("User name displayed for sign out : " + value, true);
    if (value) {
        driver.findElement(By.id("gbgs4dn")).click();
    } else {
        WebElement signOutElement = DriverConfig.getDriver().findElement(By.partialLinkText(emailUserName));
        signOutElement.click();
    }
    smallWait();

    DriverConfig.setLogString("Click Signout", true);
    driver.findElement(By.id("gb_71")).click();

    mediumWait();
    mediumWait();

    return tempPassword;
}

From source file:com.ecofactor.qa.automation.util.mail.Gmail.java

License:Open Source License

/**
 * Delete first mail.//from   w  w w. j  av  a 2 s. c  om
 * @param driver the driver
 */
public void deleteFirstMail(WebDriver driver) {

    DriverConfig.setLogString("Delete First Mail", true);
    DriverConfig.setLogString("Click Inbox", true);
    WebElement inboxElement = DriverConfig.getDriver().findElement(By.partialLinkText("Inbox"));
    inboxElement.click();
    mediumWait();

    DriverConfig.setLogString("Click Subject of Email.", true);
    boolean subjectDisplayed = isDisplayedByCSS(driver, ".ae4.UI.UJ", MEDIUM_TIMEOUT);
    if (subjectDisplayed) {
        WebElement webElement1 = driver.findElement(By.cssSelector(".ae4.UI.UJ"));
        if (!webElement1.getText().contains("No new mail")) {

            WebElement firstElement2 = null;
            if (webElement1 != null && webElement1.findElements(By.tagName(TAG_BOLD)) != null
                    && webElement1.findElements(By.tagName(TAG_BOLD)).size() > 0) {
                firstElement2 = webElement1.findElements(By.tagName(TAG_BOLD)).get(0);
            } else {
                firstElement2 = webElement1.findElements(By.cssSelector("td.yX.xY")).get(0);
            }

            if (firstElement2 != null && firstElement2.isDisplayed()) {
                firstElement2.click();
                mediumWait();

                DriverConfig.setLogString("Delete the Email", true);
                if (driver.findElements(By.cssSelector("div.ar9.T-I-J3.J-J5-Ji")) != null
                        && driver.findElements(By.cssSelector("div.ar9.T-I-J3.J-J5-Ji")).size() == 2) {
                    DriverConfig.setLogString("Click delete old mails", true);
                    WebElement webElement2 = driver.findElements(By.cssSelector("div.ar9.T-I-J3.J-J5-Ji"))
                            .get(1);
                    webElement2.click();
                } else {
                    DriverConfig.setLogString("Click delete old mails", true);
                    smallWait();
                    WebElement webElement2 = driver.findElements(By.cssSelector("div.ar9.T-I-J3.J-J5-Ji"))
                            .get(1);
                    webElement2.click();
                }

                smallWait();
            }
        }

    }
}

From source file:com.ecofactor.qa.automation.util.mail.GmailForNewUser.java

License:Open Source License

/**
 * Gets the changed password.//w  ww.  ja  v a  2  s  .c o m
 * @param url the url
 * @param emailUserName the email user name
 * @param emailPassword the email password
 * @param subject the subject
 * @param boldIndex the bold index
 * @param pwdIndex the pwd index
 * @return the changed password
 */
public String getChangedPassword(String url, String emailUserName, String emailPassword, String subject,
        int boldIndex, int pwdIndex) {

    if (gmailDriver == null) {
        gmailDriver = new ChromeDriver();
    }

    String tempPassword = null;

    largeWait();
    DriverConfig.setLogString("Load Email portal URL at change password", true);
    DriverConfig.setLogString("URL : " + url + "" + emailUserName, true);
    gmailDriver.navigate().to(url + "" + emailUserName);
    largeWait();

    boolean session = isDisplayedById(gmailDriver, "Passwd", MEDIUM_TIMEOUT);
    if (session) {
        DriverConfig.setLogString(
                "Enter username and password for Email(" + emailUserName + "/" + emailPassword + ")", true);
        if (isDisplayedById(gmailDriver, "reauthEmail", SHORT_TIMEOUT)
                && gmailDriver.findElement(By.id("reauthEmail")).getText().equalsIgnoreCase(emailUserName)) {
            clearAndInput(gmailDriver, By.id("Passwd"), emailPassword);
        } else {
            clearAndInput(gmailDriver, By.id("Email"), emailUserName);
            clearAndInput(gmailDriver, By.id("Passwd"), emailPassword);
        }

        mediumWait();
        WebElement signInButtonElement = gmailDriver.findElement(By.id("signIn"));
        DriverConfig.setLogString("click Sign In button", true);
        signInButtonElement.click();
        largeWait();
        boolean button = isDisplayedById(gmailDriver, "no-button", MEDIUM_TIMEOUT);
        if (button) {
            WebElement buttonElement = gmailDriver.findElement(By.id("no-button"));
            buttonElement.click();
            mediumWait();
        }
    }

    isDisplayedByCSS(gmailDriver, ".aio.UKr6le", MEDIUM_TIMEOUT);
    DriverConfig.setLogString("Click Inbox.", true);
    WebElement inboxElement = gmailDriver.findElement(By.partialLinkText("Inbox"));
    inboxElement.click();
    largeWait();

    DriverConfig.setLogString("Click Subject of Email.", true);
    DriverConfig.setLogString("Subject of Email : " + subject, true);
    WebElement webElement = gmailDriver.findElement(By.cssSelector(".ae4.UI.UJ"));
    List<WebElement> tagElement = webElement.findElements(By.tagName(TAG_BOLD));
    WebElement firstElement = tagElement.get(0);
    if (firstElement != null && firstElement.isDisplayed()
            && firstElement.getText().equalsIgnoreCase(subject)) {
        firstElement.click();
        largeWait();
    }

    DriverConfig.setLogString("Get temporary Password/activation link from Email.", true);
    if (boldIndex == 1) {
        WebElement divBodyElement = gmailDriver.findElement(By.xpath("//*[contains(@class,'adO')]"));
        if (pwdIndex == 1) {
            WebElement pwdElement = divBodyElement.findElements(By.tagName(TAG_STRONG)).get(0);
            tempPassword = pwdElement.getText();
            DriverConfig.setLogString("Temporary password got from email " + tempPassword, true);
        } else {
            WebElement pwdElement = divBodyElement.findElements(By.tagName(TAG_ANCHOR)).get(0);
            tempPassword = pwdElement.getText();
            DriverConfig.setLogString("Activation link got from email " + tempPassword, true);
        }
    } else if (boldIndex == 0) {
        DriverConfig.setLogString("Header Tag", true);
        WebElement divBodyElement = gmailDriver.findElement(By.className("gs"));
        List<WebElement> headerElement = divBodyElement.findElements(By.tagName("strong"));
        for (WebElement webelement : headerElement) {
            if (webelement.isDisplayed()) {
                tempPassword = webelement.getText();
                DriverConfig.setLogString("Temporary password got from email " + tempPassword, true);
            }
        }
    }
    mediumWait();

    deleteFirstMail(gmailDriver);

    DriverConfig.setLogString("Click user for Signout option", true);
    boolean value = isDisplayedById(gmailDriver, "gbgs4dn", MEDIUM_TIMEOUT);
    DriverConfig.setLogString("User name displayed for sign out : " + value, true);
    if (value) {
        gmailDriver.findElement(By.id("gbgs4dn")).click();
    } else {
        WebElement signOutElement = gmailDriver.findElement(By.partialLinkText(emailUserName));
        signOutElement.click();
    }
    smallWait();

    DriverConfig.setLogString("Click Signout", true);
    gmailDriver.findElement(By.id("gb_71")).click();

    mediumWait();
    mediumWait();
    gmailDriver.close();
    gmailDriver.quit();
    gmailDriver = null;
    return tempPassword;
}

From source file:com.ecofactor.qa.automation.util.mail.GmailForNewUser.java

License:Open Source License

/**
 * Delete first mail.//from  w  w w . j a va2s.  co  m
 * @param driver the driver
 */
public void deleteFirstMail(WebDriver driver) {

    DriverConfig.setLogString("Delete First Mail", true);
    DriverConfig.setLogString("Click Inbox", true);
    WebElement inboxElement = driver.findElement(By.partialLinkText("Inbox"));
    inboxElement.click();
    mediumWait();

    DriverConfig.setLogString("Click Subject of Email.", true);
    // boolean subjectDisplayed=isDisplayedByTagName(driver, TAG_BOLD, MEDIUM_TIMEOUT);
    boolean subjectDisplayed = isDisplayedByCSS(driver, ".ae4.UI.UJ", MEDIUM_TIMEOUT);
    if (subjectDisplayed) {
        WebElement webElement1 = driver.findElement(By.cssSelector(".ae4.UI.UJ"));
        // WebElement webElement1 = driver.findElement(By.xpath(".//*[span]"));
        if (!webElement1.getText().contains("No new mail")) {

            WebElement firstElement2 = null;
            if (webElement1 != null && webElement1.findElements(By.tagName(TAG_BOLD)) != null
                    && webElement1.findElements(By.tagName(TAG_BOLD)).size() > 0) {
                firstElement2 = webElement1.findElements(By.tagName(TAG_BOLD)).get(0);
            } else {
                firstElement2 = webElement1.findElements(By.cssSelector("td.yX.xY")).get(0);
            }

            if (firstElement2 != null && firstElement2.isDisplayed()) {
                firstElement2.click();
                mediumWait();

                DriverConfig.setLogString("Delete the Email", true);
                if (driver.findElements(By.cssSelector("div.ar9.T-I-J3.J-J5-Ji")) != null
                        && driver.findElements(By.cssSelector("div.ar9.T-I-J3.J-J5-Ji")).size() == 2) {
                    DriverConfig.setLogString("Click delete old mails", true);
                    WebElement webElement2 = driver.findElements(By.cssSelector("div.ar9.T-I-J3.J-J5-Ji"))
                            .get(1);
                    webElement2.click();
                } else {
                    DriverConfig.setLogString("Click delete old mails", true);
                    smallWait();
                    WebElement webElement2 = driver.findElements(By.cssSelector("div.ar9.T-I-J3.J-J5-Ji"))
                            .get(1);
                    webElement2.click();
                }

                smallWait();
            }
        }

    }

}

From source file:com.ecofactor.qa.automation.util.mail.OutlookMail.java

License:Open Source License

/**
 * Gets the changed password.//from   w  w  w  .j  av a 2 s. com
 * @param driver the driver
 * @param url the url
 * @param emailUserName the email user name
 * @param emailPassword the email password
 * @param subject the subject
 * @param boldIndex the bold index
 * @return the changed password
 */
public String getChangedPassword(String url, String emailUserName, String emailPassword, String subject,
        int boldIndex) {

    WebDriver driver = driverConfig.getDriver();

    DriverConfig.setLogString("Load Email portal URL.", true);
    driver.navigate().to(url);
    largeWait();

    DriverConfig.setLogString("Enter Username/Password for Email.", true);
    driver.findElement(By.id("cred_userid_inputtext")).sendKeys(emailUserName);
    driver.findElement(By.id("cred_password_inputtext")).sendKeys(emailPassword);

    smallWait();
    DriverConfig.setLogString("Click Login.", true);
    WebElement signInButtonElement = driver.findElement(By.cssSelector("#cred_sign_in_button"));
    DriverConfig.setLogString("send keys to login", true);
    signInButtonElement.sendKeys(Keys.RETURN);
    largeWait();
    DriverConfig.setLogString("click btn", true);
    signInButtonElement.click();
    largeWait();

    DriverConfig.setLogString("Click Inbox.", true);
    WebElement outLookMenu = retrieveElementByTagText(driver, TAG_SPAN, "Outlook");
    if (outLookMenu != null && outLookMenu.isDisplayed()) {
        outLookMenu.click();
        mediumWait();
    }

    DriverConfig.setLogString("Click Subject of Email.", true);
    List<WebElement> subElements = retrieveElementsByTagText(driver, TAG_SPAN, subject);
    if (subElements.size() > 0) {
        subElements.get(0).click();
        mediumWait();
    }
    largeWait();

    DriverConfig.setLogString("Get temporary Password from Email.", true);
    WebElement divBodyElement = driver.findElement(By.id("Item.MessagePartBody"));
    mediumWait();
    WebElement pwdElement = divBodyElement.findElements(By.tagName(TAG_BOLD)).get(boldIndex);
    String tempPassword = pwdElement.getText();
    DriverConfig.setLogString("Temporary password got from email " + tempPassword, true);

    DriverConfig.setLogString("Click user for Signout option", true);
    WebElement menuElement = retrieveElementByAttributeValue(driver, TAG_BUTTON, ATTR_CLASS,
            "button _hl_2 _hl_e");
    menuElement.click();
    smallWait();

    DriverConfig.setLogString("Click Signout", true);
    WebElement signOut = retrieveElementByTagText(driver, TAG_SPAN, "sign out", MEDIUM_TIMEOUT);
    signOut.click();
    smallWait();

    return tempPassword;
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Utility to check weather the particular field is displayed or not.
 * @param driver the driver//  w w w.jav  a  2s  .com
 * @param tagName the tag name
 * @param timeOut the time out
 * @return boolean
 */
public static boolean isDisplayedByTagName(final WebDriver driver, final String tagName, final int timeOut) {

    boolean isLoaded = false;
    isLoaded = (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {

            return d.findElement(By.tagName(tagName)).isDisplayed();
        }
    });
    return isLoaded;
}