List of usage examples for org.openqa.selenium WebElement getAttribute
String getAttribute(String name);
From source file:com.ecofactor.qa.automation.newapp.page.impl.TstatControlUIPageImpl.java
License:Open Source License
/** * Opacity value.//from ww w . j ava2 s. c o m * @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 .j a va2s . 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.platform.util.Pageutil.java
License:Open Source License
/** * Gets the element by its attr./* w ww . j a va 2 s.c o m*/ * @param driver the driver * @param locator the locator * @param attributeName the attribute name * @param attributeValue the attribute value * @param timeout the timeout * @return the element by attr */ public static WebElement getElementByAttr(final WebDriver driver, final By locator, final String attributeName, final String attributeValue, final CustomTimeout timeout) { WebElement elementAttrValue = null; for (final WebElement webElement : getElements(driver, locator, timeout)) { final String valueAttribute = webElement.getAttribute(attributeName); if (valueAttribute.trim().equalsIgnoreCase(attributeValue)) { elementAttrValue = webElement; } } return elementAttrValue; }
From source file:com.ecofactor.qa.automation.platform.util.Pageutil.java
License:Open Source License
/** * Gets the element by attr contains.//from w w w .j a va2s . com * @param driver the driver * @param locator the locator * @param attributeValue the attribute value * @param attributeName the attribute name * @param timeout the timeout * @return the element by attr contains */ public static WebElement getElementByAttrContains(final WebDriver driver, final By locator, final String attributeValue, final String attributeName, final CustomTimeout timeout) { WebElement elementAttrValue = null; for (final WebElement webElement : getElements(driver, locator, timeout)) { final String valueAttribute = webElement.getAttribute(attributeName); if (valueAttribute.trim().contains(attributeValue)) { elementAttrValue = webElement; } } return elementAttrValue; }
From source file:com.ecofactor.qa.automation.platform.util.Pageutil.java
License:Open Source License
/** * Gets the element by sub element attr. * @param driver the driver/* w w w .j a v a2s. co m*/ * @param subElement the sub element * @param locator the locator * @param attributeName the attribute name * @param attributeValue the attribute value * @param timeout the timeout * @return the element by sub element attr */ public static WebElement getElementBySubElementAttr(final WebDriver driver, final WebElement subElement, final By locator, final String attributeName, final String attributeValue, final CustomTimeout timeout) { WebElement elementAttrValue = null; final List<WebElement> elementList = getElementsBySubElement(driver, subElement, locator, timeout); for (final WebElement webElement : elementList) { final String valueAttribute = webElement.getAttribute(attributeName); if (valueAttribute.trim().equalsIgnoreCase(attributeValue)) { elementAttrValue = webElement; } } return elementAttrValue; }
From source file:com.ecofactor.qa.automation.qtc.page.TaskPageImpl.java
License:Open Source License
/** * Click next2./*from w w w . j a va 2s . 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.PageUtil.java
License:Open Source License
/** * Sets the value.//ww w. j a v a 2s . c om * @param driver the driver * @param cssSelector the css selector * @param value the value * @param index the index */ public static void setValueByCSS(WebDriver driver, String cssSelector, String value, int index) { if (isDisplayedByCSS(driver, cssSelector, 10)) { List<WebElement> inputs = driver.findElements(By.cssSelector(cssSelector)); int count = 0; for (WebElement input : inputs) { if (input.isDisplayed() && input.isEnabled()) { if (count == index) { input.clear(); input.sendKeys(value); logger.info("Count " + count + ", " + input.getAttribute("id")); break; } ++count; } } } }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * <b> verify the particular value is displayed according to the attribute</b>. * @param driver the driver/*from w w w . ja va 2 s .c o m*/ * @param tagName the tag name * @param attributeName the attribute name * @param attributeValue the attribute value * @return the web element */ public static WebElement retrieveElementByAttributeValue(final WebDriver driver, final String tagName, final String attributeName, final String attributeValue) { WebElement element = null; List<WebElement> elementList = driver.findElements(By.tagName(tagName)); for (WebElement webElement : elementList) { String valueAttribute = webElement.getAttribute(attributeName.trim()); if (valueAttribute.trim().equalsIgnoreCase(attributeValue)) return webElement; } return element; }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Retrieve element by attribute value.// w ww. j a va 2 s.c o m * @param driver the driver * @param tagName the tag name * @param attributeName the attribute name * @param attributeValue the attribute value * @param timeOut the time out * @return the web element */ public static WebElement retrieveElementByAttributeValue(final WebDriver driver, final String tagName, final String attributeName, final String attributeValue, int timeOut) { elementAttrValue = null; (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { boolean isLoaded = false; List<WebElement> elementList = driver.findElements(By.tagName(tagName)); for (WebElement webElement : elementList) { String valueAttribute = webElement.getAttribute(attributeName.trim()); if (valueAttribute.trim().equalsIgnoreCase(attributeValue)) { elementAttrValue = webElement; isLoaded = true; break; } } return isLoaded; } }); return elementAttrValue; }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Contain by attribute value.// ww w .j av a 2 s. co m * @param driver the driver * @param tagName the tag name * @param attributeName the attribute name * @param attributeValue the attribute value * @param timeOut the time out * @return the web element */ public static WebElement containByAttributeValue(final WebDriver driver, final String tagName, final String attributeName, final String attributeValue, int timeOut) { elementAttrValue = null; (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { boolean isLoaded = false; List<WebElement> elementList = driver.findElements(By.tagName(tagName)); for (WebElement webElement : elementList) { String valueAttribute = webElement.getAttribute(attributeName.trim()); if (valueAttribute.trim().contains(attributeValue)) { elementAttrValue = webElement; isLoaded = true; break; } } return isLoaded; } }); return elementAttrValue; }