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
/** * Retrieve element by contains of attribute value. * @param driver the driver/* w w w . ja v a2 s. com*/ * @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 retrieveElementByContainsOfAttributeValue(final WebDriver driver, final String tagName, final String attributeName, final String attributeValue, final int timeOut) { elementContainsAttrValue = 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 != null && valueAttribute.trim().contains(attributeValue)) { elementContainsAttrValue = webElement; isLoaded = true; break; } } return isLoaded; } }); return elementContainsAttrValue; }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Retrieve elements by contains of attribute value. * @param driver the driver/*from w w w . j a va2 s.c om*/ * @param tagName the tag name * @param attributeName the attribute name * @param attributeValue the attribute value * @return the list */ public static List<WebElement> retrieveElementsByContainsOfAttributeValue(final WebDriver driver, final String tagName, final String attributeName, final String attributeValue) { List<WebElement> elementListGroup = new ArrayList<WebElement>(); List<WebElement> elementList = driver.findElements(By.tagName(tagName)); for (WebElement webElement : elementList) { String valueAttribute = webElement.getAttribute(attributeName.trim()); if (valueAttribute != null && valueAttribute.trim().contains(attributeValue)) { elementContainsAttrValue = webElement; elementListGroup.add(webElement); } } return elementListGroup; }
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 va2 s .c o m*/ * @param idValue the id value * @param textValue the text value * @return the web element */ public static WebElement retrieveElementByIdText(final WebDriver driver, final String idValue, final String textValue) { WebElement element = null; List<WebElement> elementList = driver.findElements(By.id(idValue)); for (WebElement webElement : elementList) { String value = webElement.getText(); if (value.trim().equalsIgnoreCase(textValue)) return webElement; } return element; }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Retrieve element by id./* www.jav a2 s . c o m*/ * * @param driver the driver * @param idValue the id value * @return the web element */ public static WebElement retrieveElementById(final WebDriver driver, final String idValue) { WebElement element = null; List<WebElement> elementList = driver.findElements(By.id(idValue)); for (WebElement webElement : elementList) { if (webElement != null) return webElement; } return element; }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Retrieve element by tag text.//from ww w .j av a 2 s.c o m * @param driver the driver * @param tagName the tag name * @param textValue the text value * @param timeOut the time out * @return the web element */ public static WebElement retrieveElementByTagText(final WebDriver driver, final String tagName, final String textValue, final int timeOut) { elementTagText = 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 value = webElement.getText(); if (value.trim().equalsIgnoreCase(textValue)) { elementTagText = webElement; isLoaded = true; break; } } return isLoaded; } }); /* * WebElement element = null; List<WebElement> elementList = * driver.findElements(By.tagName(tagName)); for (WebElement webElement : elementList) { * String value = webElement.getText(); if(value.trim().equalsIgnoreCase(textValue)) return * webElement; } */ return elementTagText; }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Contains by tag text.// ww w . j a v a2 s . c o m * @param driver the driver * @param tagName the tag name * @param textValue the text value * @param timeOut the time out * @return the web element */ public static WebElement containsByTagText(final WebDriver driver, final String tagName, final String textValue, final int timeOut) { elementTagText = 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 value = webElement.getText(); if (value.trim().contains(textValue)) { elementTagText = webElement; isLoaded = true; break; } } return isLoaded; } }); /* * WebElement element = null; List<WebElement> elementList = * driver.findElements(By.tagName(tagName)); for (WebElement webElement : elementList) { * String value = webElement.getText(); if(value.trim().equalsIgnoreCase(textValue)) return * webElement; } */ return elementTagText; }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Retrieve element by tag text./* w w w .j a v a 2s . c o m*/ * @param driver the driver * @param tagName the tag name * @param textValue the text value * @return the web element */ public static WebElement retrieveElementByTagText(final WebDriver driver, final String tagName, final String textValue) { WebElement element = null; List<WebElement> elementList = driver.findElements(By.tagName(tagName)); for (WebElement webElement : elementList) { String value = webElement.getText(); if (value.trim().equalsIgnoreCase(textValue)) return webElement; } return element; }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Retrieve elements by tag text.//from ww w.ja v a2 s . c o m * @param driver the driver * @param tagName the tag name * @param textValue the text value * @return the list */ public static List<WebElement> retrieveElementsByTagText(final WebDriver driver, final String tagName, final String textValue) { List<WebElement> elementList = driver.findElements(By.tagName(tagName)); List<WebElement> listElement = new ArrayList<WebElement>(); for (WebElement webElement : elementList) { String valueAttribute = webElement.getText(); if (valueAttribute.trim().equalsIgnoreCase(textValue)) listElement.add(webElement); } return listElement; }
From source file:com.formkiq.web.WorkflowEditorControllerIntegrationTest.java
License:Apache License
/** * Click Delete Field Button./*from www. j a v a2s .c om*/ * @param fieldid {@link String} */ private void clickDeleteFieldButton(final String fieldid) { WebElement we = findElementsBy("button", "data-uuid", fieldid).stream() .filter(s -> s.getAttribute("class").contains("form-field-delete")).findFirst().get(); we.click(); waitUntil(new Predicate<WebDriver>() { @Override public boolean apply(final WebDriver d) { By by = getBy("button", "data-uuid", fieldid); return d.findElements(by).isEmpty(); } }); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlPage3Test.java
License:Apache License
/** * Test for 3306491./*from w ww . j a va2 s .c om*/ * @throws Exception if an error occurs */ @Test public void formElementCreatedFromJavascript() throws Exception { final String html = "<html>\n" + "<head>\n" + "<script type='text/javascript'>\n" + " function modifyForm() {\n" + " var myForm = document.forms['test_form'];\n" + " var el = document.createElement('input');\n" + " el.setAttribute('addedBy','js');\n" + " el.name = 'myHiddenField';\n" + " el.value = 'myValue';\n" + " el.type = 'hidden';\n" + " myForm.appendChild(el);\n" + "}\n" + "</script>\n" + "</head>\n" + "<body onLoad='modifyForm()'>\n" + " <form id='test_form' action='http://www.sourceforge.com/' method='post'>\n" + " <input type='submit' value='click'/>\n" + " </form>\n" + "</body>\n" + "</html>"; final WebDriver driver = loadPage2(html); final List<WebElement> elements = driver.findElements(By.xpath("//*")); assertEquals(7, elements.size()); assertEquals("html", elements.get(0).getTagName()); assertEquals("head", elements.get(1).getTagName()); assertEquals("script", elements.get(2).getTagName()); assertEquals("body", elements.get(3).getTagName()); assertEquals("form", elements.get(4).getTagName()); assertEquals("input", elements.get(5).getTagName()); final WebElement input = elements.get(6); assertEquals("input", input.getTagName()); assertEquals("myHiddenField", input.getAttribute("name")); assertEquals("js", input.getAttribute("addedBy")); assertEquals("js", input.getAttribute("addedby")); }