List of usage examples for org.openqa.selenium WebElement findElements
@Override List<WebElement> findElements(By by);
From source file:com.epam.jdi.uitests.mobile.appium.elements.complex.MultiSelector.java
License:Open Source License
protected void clearAction() { if (!hasLocator() && allLabels() == null) throw exception("Can't clear options. No optionsNamesLocator and allLabelsLocator found"); if (getLocator().toString().contains("%s")) throw exception( "Can't clear options. Specify allLabelsLocator or fix optionsNamesLocator (should not contain '%s')"); if (allLabels() != null) { clearElements(allLabels().avatar.searchAll().getElements()); return;/* www . j av a 2 s. c o m*/ } List<WebElement> elements = getAvatar().searchAll().getElements(); WebElement element = elements.get(0); if (elements.size() == 1 && element.getTagName().equals("select")) if (getSelector().getOptions().size() > 0) { getSelector().deselectAll(); return; } else throw exception("<select> tag has no <option> tags. Please Clarify element locator (%s)", this); if (elements.size() == 1 && element.getTagName().equals("ul")) elements = element.findElements(By.tagName("li")); clearElements(elements); }
From source file:com.epam.jdi.uitests.web.selenium.elements.complex.BaseSelector.java
License:Open Source License
protected Clickable getElement(String name) { if (!hasLocator() && allLabels() == null) throw exception("Can't find option '%s'. No optionsNamesLocator and allLabelsLocator found", name); if (hasLocator() && getLocator().toString().contains("%s")) return new GetElementType(fillByTemplate(getLocator(), name), this).get(Clickable.class); if (allLabels() != null) return allLabels().getLocator().toString().contains("%s") ? new GetElementType(fillByTemplate(allLabels().getLocator(), name), this).get(Clickable.class) : getFromList(allLabels().avatar.searchAll().getElements(), name); List<WebElement> elements = getAvatar().searchAll().getElements(); WebElement element = elements.get(0); if (elements.size() == 1 && element.getTagName().equals("select")) if (getSelector().getOptions().size() > 0) { getSelector().selectByVisibleText(name); return null; } else//from w w w . ja va2 s .c o m throw exception("<select> tag has no <option> tags. Please Clarify element locator (%s)", this); if (elements.size() == 1 && element.getTagName().equals("ul")) elements = element.findElements(By.tagName("li")); return getFromList(elements, name); }
From source file:com.epam.jdi.uitests.web.selenium.elements.complex.BaseSelector.java
License:Open Source License
protected Clickable getElement(int num) { if (!hasLocator() && allLabels() == null) throw exception("Can't find option '%s'. No optionsNamesLocator and allLabelsLocator found", num); if (allLabels() != null) return selectFromList(allLabels().avatar.searchAll().getElements(), num); if (getLocator().toString().contains("%s")) return new GetElementType(fillByTemplate(getLocator(), num), this).get(Clickable.class); List<WebElement> elements = getAvatar().searchAll().getElements(); WebElement element = elements.get(0); if (elements.size() == 1 && element.getTagName().equals("select")) if (getSelector().getOptions().size() > 0) { getSelector().selectByIndex(num - 1); return null; } else/*from w w w .j a va 2s .c om*/ throw exception("<select> tag has no <option> tags. Please Clarify element locator (%s)", this); if (elements.size() == 1 && element.getTagName().equals("ul")) elements = element.findElements(By.tagName("li")); return selectFromList(elements, num); }
From source file:com.etouch.cisco.common.CiscoMainPage.java
public void ValidECU(TestParameters input) throws InterruptedException { final int MAX_WAIT = 50; String tempecu = ""; try {/*from w w w .ja va2 s . c o m*/ //SignIn(input); jsx.executeScript("window.document.getElementById('newCalculation').click()"); ((TextBox) webPage.findObject(ObjectType.TextBox, MainPageElements.ServerCount_XPATH, ObjectValType.XPATH, MAX_WAIT, WaitCondition.VISIBLE)) .enterText(input.getParamMap().get("servercount")); ((TextBox) webPage.findObject(ObjectType.TextBox, MainPageElements.CPUCount_XPATH, ObjectValType.XPATH, MAX_WAIT, WaitCondition.VISIBLE)).enterText(input.getParamMap().get("cpucount")); // testing kanika - start WebElement table = webDriver.findElement(By.id(MainPageElements.TotalECU_ID)); List<WebElement> allRows = table.findElements(By.tagName("tr")); for (WebElement row : allRows) { List<WebElement> cells = row.findElements(By.tagName("td")); for (WebElement colElement : cells) { tempecu = colElement.getText(); } } totalECU = Float.parseFloat(tempecu); // testing kanika - end ((SelectBox) webPage.findObject(ObjectType.SelectBox, "selectCpu", ObjectValType.ID, MAX_WAIT, WaitCondition.VISIBLE)).selectDropDownList("E5-2650 v2"); // jsx.executeScript("document.getElementById('calculate').click()"); //////webPage.sleep(100); } catch (Exception e) { log.error(getErrMessage()); System.err.println(getErrMessage()); } }
From source file:com.galenframework.ide.tests.integration.components.galenpages.WebComponent.java
License:Apache License
@SuppressWarnings("unchecked") public T selectByText(String text) { WebElement webElement = getWebElement(); Optional<WebElement> optionElement = webElement.findElements(By.tagName("option")).stream() .filter(e -> text.equals(e.getText())).findFirst(); if (optionElement.isPresent()) { optionElement.get().click();// w w w . j a v a2 s . c o m } else { throw new RuntimeException("Couldn't find option with text \"" + text + "\" for " + getName()); } return (T) this; }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLSelectElementTest.java
License:Apache License
/** * @throws Exception if the test fails// w ww. j a v a 2s . c o m */ @Test public void deselectFromMultiple() throws Exception { final String html = "<html><body>\n" + "<select id='s' multiple>\n" + " <option selected value='one'>One</option>\n" + " <option value='two'>Two</option>\n" + " <option selected value='three'>Three</option>\n" + "</select>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final WebElement multiSelect = driver.findElement(By.id("s")); final List<WebElement> options = multiSelect.findElements(By.tagName("option")); WebElement option = options.get(0); assertTrue(option.isSelected()); option.click(); assertFalse(option.isSelected()); option.click(); assertTrue(option.isSelected()); option = options.get(2); assertTrue(option.isSelected()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLSelectElementTest.java
License:Apache License
/** * @throws Exception if the test fails/*from w w w . j av a2 s .c o m*/ */ @Test public void optionClick() throws Exception { final String html = "<html><body>\n" + "<select id='s' multiple>\n" + " <option selected value='one'>One</option>\n" + " <option value='two'>Two</option>\n" + " <option selected value='three'>Three</option>\n" + "</select>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final WebElement multiSelect = driver.findElement(By.id("s")); final List<WebElement> options = multiSelect.findElements(By.tagName("option")); assertTrue(options.get(0).isSelected()); assertFalse(options.get(1).isSelected()); assertTrue(options.get(2).isSelected()); options.get(0).click(); assertFalse(options.get(0).isSelected()); assertFalse(options.get(1).isSelected()); assertTrue(options.get(2).isSelected()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLSelectElementTest.java
License:Apache License
/** * @throws Exception if the test fails/*from w w w.j a v a 2 s . c om*/ */ @Test // https://github.com/mozilla/geckodriver/issues/584 @BuggyWebDriver(FF) public void optionClickActions() throws Exception { final String html = "<html><body>\n" + "<select id='s' multiple>\n" + " <option selected value='one'>One</option>\n" + " <option value='two'>Two</option>\n" + " <option selected value='three'>Three</option>\n" + "</select>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final WebElement multiSelect = driver.findElement(By.id("s")); final List<WebElement> options = multiSelect.findElements(By.tagName("option")); assertTrue(options.get(0).isSelected()); assertFalse(options.get(1).isSelected()); assertTrue(options.get(2).isSelected()); new Actions(driver).click(options.get(0)).perform(); assertTrue(options.get(0).isSelected()); assertFalse(options.get(1).isSelected()); assertFalse(options.get(2).isSelected()); }
From source file:com.gargoylesoftware.htmlunit.libraries.DojoTestBase.java
License:Apache License
void test(final String module) throws Exception { try {/*from w w w .j ava 2s. c o m*/ final WebDriver webdriver = getWebDriver(); final String url = URL_FIRST + "util/doh/runner.html?testModule=" + module; webdriver.get(url); final long runTime = 60 * DEFAULT_WAIT_TIME; final long endTime = System.currentTimeMillis() + runTime; // wait a bit to let the tests start Thread.sleep(DEFAULT_WAIT_TIME); String status = getResultElementText(webdriver); while (!"Stopped".equals(status)) { Thread.sleep(DEFAULT_WAIT_TIME); if (System.currentTimeMillis() > endTime) { fail("Test runs too long (longer than " + runTime / 1000 + "s)"); } status = getResultElementText(webdriver); } Thread.sleep(100); // to make tests a bit more stable final WebElement output = webdriver.findElement(By.id("logBody")); final List<WebElement> lines = output.findElements(By.xpath(".//div")); final StringBuilder result = new StringBuilder(); for (WebElement webElement : lines) { final String text = webElement.getText(); if (StringUtils.isNotBlank(text)) { result.append(text); result.append("\n"); } } String expFileName = StringUtils.replace(module, ".", ""); expFileName = StringUtils.replace(expFileName, "_", ""); String expected = loadExpectation(expFileName); expected = StringUtils.replace(expected, "\r\n", "\n"); assertEquals(normalize(expected), normalize(result.toString())); // assertEquals(expected, result.toString()); } catch (final Exception e) { e.printStackTrace(); Throwable t = e; while ((t = t.getCause()) != null) { t.printStackTrace(); } throw e; } }
From source file:com.github.codewrs.selenium.FindElementAdvanced.java
License:Open Source License
/** * Find all elements within the WebElement using the given mechanism. * Returns WebElement by matching with index of the WebElement. * @param webElement Base WebElement containing the WebElements. * @param by The locating mechanism./*from w w w . j a v a2s . co m*/ * @param elementIndex Index of the WebElement to find. * @param wait Explicit Wait Time. * @return WebElement or null if nothing matches. */ protected WebElement findElementOnList(WebElement webElement, By by, int elementIndex, WebDriverWait wait) { try { List<WebElement> elementList = webElement.findElements(by); wait.until(ExpectedConditions.visibilityOfAllElements(elementList)); int listSize = elementList.size(); System.out.println("The number of element counted is : " + listSize); if (listSize > 0) { int i = 0; for (WebElement ele : elementList) { if (elementIndex == i) { System.out.println("The returned WebElement text : " + ele.getText()); return ele; } i++; } } } catch (NoSuchElementException e) { System.out.println("No Element found."); } System.out.println("No Element found."); return null; }