List of usage examples for org.openqa.selenium WebDriver findElements
@Override List<WebElement> findElements(By by);
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// ww w . j av a 2 s . co m * @param cssSelector the css selector * @param timeOut the time out * @return boolean */ public static boolean isDisplayedByCSS(final WebDriver driver, final String cssSelector, final int timeOut) { boolean isLoaded = false; try { isLoaded = (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { List<WebElement> elements = d.findElements(By.cssSelector(cssSelector)); boolean displayed = false; for (WebElement element : elements) { displayed = element.isDisplayed(); if (displayed) { break; } } return displayed; } }); } catch (TimeoutException te) { isLoaded = false; } return isLoaded; }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Sets the value.//from w ww .ja v a2 s . co m * @param driver the driver * @param cssSelector the css selector * @param value the value */ public static void setValueByCSS(WebDriver driver, String cssSelector, String value) { if (isDisplayedByCSS(driver, cssSelector, 10)) { List<WebElement> inputs = driver.findElements(By.cssSelector(cssSelector)); for (WebElement input : inputs) { if (input.isDisplayed() && input.isEnabled()) { input.clear(); input.sendKeys(value); } } } }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Sets the value.//ww w . j a v a2 s . com * @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
/** * Select option by value./*w ww.j av a2 s.c o m*/ * @param driver the driver * @param cssSelector the css selector * @param selectValue the select value */ public static void selectOptionValueByCSS(final WebDriver driver, final String cssSelector, final String selectValue) { logger.info("Select css selector:" + cssSelector + " ; selectValue" + selectValue); List<WebElement> elements = driver.findElements(By.cssSelector(cssSelector)); for (WebElement element : elements) { if (element.isDisplayed() && element.isEnabled()) { Select select = new Select(element); select.selectByValue(selectValue); } } }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Is elements displayed by class Name. . . * @param driver the driver/*from w ww. j a v a 2s.c o m*/ * @param fieldname the fieldname * @param timeOut the time out * @return boolean */ public static boolean isMultipleClassNameDisplayed(final WebDriver driver, final String fieldname, final int timeOut) { boolean isLoaded = false; try { isLoaded = (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { List<WebElement> scheduleChartElmtList = driver.findElements(By.className(fieldname)); if (scheduleChartElmtList.size() > 0) { return true; } return false; } }); } catch (TimeoutException te) { isLoaded = false; } return isLoaded; }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Multiple elements displayed by Tag Name. * @param driver the driver/*from www . j a v a 2s . com*/ * @param fieldname the fieldname * @param timeOut the time out * @return boolean */ public static boolean isMultipleTagNameDisplayed(final WebDriver driver, final String fieldname, final int timeOut) { boolean isLoaded = false; isLoaded = (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { List<WebElement> elmtList = driver.findElements(By.tagName(fieldname)); boolean returnValue = false; returnValue = elmtList != null && elmtList.size() > 0 ? true : false; return returnValue; } }); return isLoaded; }
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 ww w .ja v a2 s.co 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 w w. j a va 2 s . c om*/ * @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./*from w w w . ja v a 2 s.com*/ * @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; }
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 . j a va2 s . com * @param tagName the tag name * @param attributeName the attribute name * @param attributeValue the attribute value * @return the list */ public static List<WebElement> retrieveElementsByAttributeValueList(final WebDriver driver, final String tagName, final String attributeName, final String attributeValue) { List<WebElement> elementList = driver.findElements(By.tagName(tagName)); List<WebElement> listElement = new ArrayList<WebElement>(); for (WebElement webElement : elementList) { String valueAttribute = webElement.getAttribute(attributeName.trim()); if (valueAttribute.trim().equalsIgnoreCase(attributeValue)) listElement.add(webElement); } return listElement; }