List of usage examples for org.openqa.selenium WebElement findElements
@Override List<WebElement> findElements(By by);
From source file:com.pineapple.eckotur.web.test.DeleteOffer.java
@Test public void deletecart() throws Exception { boolean success = false; driver.findElement(By.partialLinkText("delete")).click(); Thread.sleep(3000);/*from w w w .j av a 2 s.c o m*/ List<WebElement> rows = driver.findElements(By.xpath("//table[contains(@id,'Table')]/tbody/tr")); for (WebElement webElement : rows) { List<WebElement> elems = webElement.findElements(By.xpath("td")); if (elems.get(0).getText().equals("Colombia") && elems.get(1).getText().equals("8000000")) { List<WebElement> buttons = elems.get(2).findElements(By.xpath("button")); buttons.get(1).click(); success = true; break; } } Thread.sleep(3000); //Se busca el objeto que fue eliminado, si se encuentra hay error al eliminar rows = driver.findElements(By.xpath("//table[contains(@id,'Table')]/tbody/tr")); if (rows.size() > 0) { for (WebElement webElement : rows) { List<WebElement> elems = webElement.findElements(By.xpath("td")); if (elems.get(0).getText().equals("Viaje al centro de la tierra") && elems.get(1).getText().equals("Web ID: 1089772")) { success = false; break; } } } Thread.sleep(3000); assertTrue(success); }
From source file:com.pramati.wavemaker.pages.ProjectCreationPage.java
License:Open Source License
/** * Click on File Sub Menu/*from w w w.j a v a2s. co m*/ * * @param subMenu */ private void clickFileSubMenu(String subMenu) { waitForElementLocatedByCSS(MENU_FILE_LIST, getTimeOutInSeconds()); List<WebElement> subMenuParentEle = basePage.getElementsByCSS(MENU_FILE_LIST); for (WebElement sMPE : subMenuParentEle) { List<WebElement> subMenuList = sMPE.findElements(By.tagName("td")); for (WebElement sML : subMenuList) { if (sML.getText().contains(subMenu)) { sML.click(); break; } } } }
From source file:com.qwazr.crawler.web.driver.BrowserDriver.java
License:Apache License
public void findRssItemLinks(SearchContext searchContext, Collection<String> linkCollection) { List<WebElement> channels = driver.findElements(By.tagName("channel")); for (WebElement channel : channels) { List<WebElement> items = channel.findElements(By.tagName("item")); for (WebElement item : items) { List<WebElement> links = item.findElements(By.tagName("link")); for (WebElement link : links) { linkCollection.add(link.getText()); }//from w w w . ja v a 2 s. c o m } } }
From source file:com.screenslicer.core.scrape.QueryForm.java
License:Open Source License
public static List<HtmlNode> load(RemoteWebDriver driver, FormLoad context) throws ActionFailed { try {/*from www. j a v a2 s. com*/ Util.get(driver, context.site, true); Util.doClicks(driver, context.preAuthClicks, null); QueryCommon.doAuth(driver, context.credentials); Util.doClicks(driver, context.preSearchClicks, null); WebElement form = driver.findElementById(context.formId); Map<HtmlNode, String> controlsHtml = new HashMap<HtmlNode, String>(); String formHtml = CommonUtil.strip(form.getAttribute("outerHTML"), false); List<WebElement> elements = new ArrayList<WebElement>(); elements.addAll(form.findElements(By.tagName("input"))); elements.addAll(form.findElements(By.tagName("button"))); elements.addAll(form.findElements(By.tagName("textarea"))); List<HtmlNode> controls = new ArrayList<HtmlNode>(); for (WebElement element : elements) { HtmlNode control = toFormControl(element); if (control != null) { controls.add(control); controlsHtml.put(control, CommonUtil.strip(element.getAttribute("outerHTML"), false)); } } elements = new ArrayList<WebElement>(); elements.addAll(form.findElements(By.tagName("select"))); for (WebElement element : elements) { HtmlNode control = toFormControl(element); if (control != null) { control.innerHtml = null; List<WebElement> options = element.findElements(By.tagName("option")); List<String> optionValues = new ArrayList<String>(); List<String> optionLabels = new ArrayList<String>(); for (WebElement option : options) { String value = option.getAttribute("value"); String label = option.getAttribute("innerHTML"); if (!CommonUtil.isEmpty(value) && !CommonUtil.isEmpty(label)) { optionValues.add(value); optionLabels.add(label); } } String multiple = element.getAttribute("multiple"); if (!CommonUtil.isEmpty(multiple) && !"false".equalsIgnoreCase(multiple)) { control.multiple = "multiple"; } else { multiple = element.getAttribute("data-multiple"); if (!CommonUtil.isEmpty(multiple) && !"false".equalsIgnoreCase(multiple)) { control.multiple = "multiple"; } } if ("select-multiple".equalsIgnoreCase(control.type)) { control.multiple = "multiple"; } control.type = null; control.optionValues = optionValues.toArray(new String[0]); control.optionLabels = optionLabels.toArray(new String[0]); controls.add(control); controlsHtml.put(control, CommonUtil.strip(element.getAttribute("outerHTML"), false)); } } loadLabels(driver, controls); loadGuids(controls); Collections.sort(controls, new ControlComparator(formHtml, controlsHtml)); return filterControls(controls); } catch (Throwable t) { Log.exception(t); throw new ActionFailed(t); } }
From source file:com.seleniumtests.uipage.htmlelements.Table.java
License:Apache License
/** * Given a row WebElement (represents a <tr> html element), returns the list of elements (<tr> or <th>) * @param row the row to analyze/* w w w . ja v a 2 s . c om*/ * @return */ public List<WebElement> getRowCells(WebElement row) { List<WebElement> cells; if (row == null) { return new ArrayList<>(); } cells = row.findElements(By.xpath(".//descendant::*[name()=\"th\" or name()=\"td\"]")); return cells; }
From source file:com.smash.revolance.ui.server.BrowserSteps.java
License:Open Source License
private boolean selectOption(String option, WebElement element) { List<WebElement> options = element.findElements(By.tagName("option")); for (WebElement _option : options) { if (_option.getText().contentEquals(option)) { _option.click();//from w w w . j a va 2 s .c om return true; } } return false; }
From source file:com.softwareonpurpose.uinavigator.UiElement.java
License:Apache License
/** * @param description String description of the elements used for logging * @param locatorType String (UiElement.LocatorType) defining Selenium locator type * @param locatorValue String value of locator * @param parent UiElement representing a parent of the requested elements * @return List of HtmlElements instantiated with the defined locator and description *///from w w w . ja v a 2 s .c o m public static List<UiElement> getList(String description, String locatorType, String locatorValue, UiElement parent) { List<UiElement> elements = new ArrayList<>(); WebElement parentElement = parent.getElement(); List<WebElement> webElements = parentElement != null ? parentElement.findElements(createLocator(locatorType, locatorValue)) : new ArrayList<WebElement>(); for (int elementOrdinal = 1; elementOrdinal <= webElements.size(); elementOrdinal++) { elements.add(UiElement.getInstance(description, locatorType, locatorValue, elementOrdinal, parent)); } return elements; }
From source file:com.technophobia.webdriver.substeps.impl.FinderWebDriverSubStepImplementations.java
License:Open Source License
/** * @param label the label of the input/* w ww. jav a 2 s .c o m*/ * @param tag the tag * @param inputType the input type * @return the web element */ public WebElement findInputInsideTag(final String label, final String tag, final String inputType) { WebElement elem = null; webDriverContext().setCurrentElement(null); // TODO - turn this into a function // look for elems with the right tag final List<WebElement> tagElems = webDriver().findElements(By.tagName(tag)); checkElements("expecting some elements of tag: " + tag, tagElems); List<WebElement> matchingElems = null; for (final WebElement tagElem : tagElems) { // does this tag contain the right text ? if (label.compareTo(tagElem.getText()) == 0) { // yes // is there a radio button inside ? final List<WebElement> inputElements = tagElem.findElements(By.tagName("input")); if (inputElements != null && !inputElements.isEmpty()) { // are they radio buttons ? for (final WebElement inputElement : inputElements) { final String type = inputElement.getAttribute("type"); if (type != null && type.compareToIgnoreCase(inputType) == 0) { // bingo if (matchingElems == null) { matchingElems = new ArrayList<WebElement>(); } matchingElems.add(inputElement); } } } } } elem = MatchingElementResultHandler.checkForOneMatchingElement( "expecting an input of type " + inputType + " inside tag [" + tag + "] with label [" + label + "]", matchingElems); webDriverContext().setCurrentElement(elem); return elem; }
From source file:com.technophobia.webdriver.substeps.impl.FinderWebDriverSubStepImplementations.java
License:Open Source License
private WebElement findParentWithChildByInternal(final By by, final By childBy, final String assertionMessage, final String findParentAssertionMessage, final String multipleChildrenMessage) { WebElement rtn;//w w w. ja v a2 s. c om List<WebElement> matchingElements = null; final List<WebElement> candidateParentElements = webDriver().findElements(by); Assert.assertNotNull(findParentAssertionMessage, candidateParentElements); Assert.assertFalse(findParentAssertionMessage, candidateParentElements.isEmpty()); for (final WebElement parent : candidateParentElements) { final List<WebElement> children = parent.findElements(childBy); // do we care if there are more than one matching child ? lets go // with no.. if (children != null && !children.isEmpty()) { if (matchingElements == null) { matchingElements = new ArrayList<WebElement>(); } matchingElements.add(parent); if (children.size() > 1) { logger.info(multipleChildrenMessage); } } } rtn = MatchingElementResultHandler.checkForOneMatchingElement(assertionMessage, matchingElements); return rtn; }
From source file:com.technophobia.webdriver.substeps.impl.FormWebDriverSubStepImplementations.java
License:Open Source License
private List<WebElement> getOptions(final WebElement select) { return select.findElements(By.tagName("option")); }