List of usage examples for org.openqa.selenium WebElement findElements
@Override List<WebElement> findElements(By by);
From source file:com.github.codewrs.selenium.FindElementAdvanced.java
License:Open Source License
/** * Find all the elements within the WebElement using the given mechanism. * Returns WebElement with the matching text. * @param webElement Base WebElement to find other WebElements. * @param by The locating mechanism.//from ww w . ja va 2 s. c o m * @param textToMatch Text to match with text of found WebElements. * @param wait Explicit Wait Time. * @return WebElement or null if nothing matches. */ protected WebElement findElementOnList(WebElement webElement, By by, String valueToMatch, 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) { for (WebElement ele : elementList) { if (ele.getText() != null) { if (ele.getText().contentEquals(valueToMatch)) { System.out.println("The returned WebElement text : " + ele.getText()); return ele; } } } } } catch (NoSuchElementException e) { System.out.println("No Element found."); } System.out.println("No Element found."); return null; }
From source file:com.github.codewrs.selenium.FindElementAdvanced.java
License:Open Source License
/** * Find all the elements within the WebElement using the given mechanism. * Returns WebElement by matching with the value of the attribute. * @param webElement Base WebElement to find other WebElements. * @param by The locating mechanism./*from ww w. jav a2 s .c o m*/ * @param attributeToSearch The attribute to locate. * @param valueToMatch Text to match with attribute's value. * @param wait Explicit Wait Time. * @return WebElement or null if nothing matches. */ protected WebElement findElementOnList(WebElement webElement, By by, String attributeToSearch, String valueToMatch, WebDriverWait wait) { try { List<WebElement> elementList = webElement.findElements(by); wait.until(ExpectedConditions.visibilityOfAllElements(elementList)); int listSize = elementList.size(); System.out.println("The number of WebElements found : " + listSize); if (listSize > 0) { for (WebElement ele : elementList) { if (ele.getAttribute(attributeToSearch) != null) { if (ele.getAttribute(attributeToSearch).contentEquals(valueToMatch)) { System.out.println("The returned WebElement text : " + ele.getText()); return ele; } } } } } catch (NoSuchElementException e) { System.out.println("No Element found."); } System.out.println("No Element found."); return null; }
From source file:com.github.codewrs.selenium.FindElementAdvanced.java
License:Open Source License
/** * Find all <tr> tags within the current table body. * Then searches <th> tags for each <tr>. * Returns <tr> WebElement by matching with <th> text. * @param tBody WebElement of the table body. * @param thTextToMatch Text to match with <th> tag's text. * @param wait Explicit Wait Time.//from w ww . j av a 2s. c o m * @return WebElement or null if nothing matches. */ protected WebElement findElementOnTable(WebElement tBody, String thTextToMatch, WebDriverWait wait) { try { List<WebElement> trList = tBody.findElements(By.tagName("tr")); wait.until(ExpectedConditions.visibilityOfAllElements(trList)); int trSize = trList.size(); if (trSize > 0) { for (WebElement webElement : trList) { List<WebElement> tdList = webElement.findElements(By.tagName("td")); int thSize = tdList.size(); if (thSize > 0) { for (WebElement ele : tdList) { if (ele.getText() != null) { if (ele.getText().equals(thTextToMatch)) { System.out.println("The returned WebElement text : " + ele.getText()); return ele; } } } } } } } catch (NoSuchElementException e) { System.out.println("No Element found."); } System.out.println("No Element found."); return null; }
From source file:com.gkopevski.fuelcheck.FuelCheckForm.java
/** * This method will crawl data from a web site. When data is fetched will be * compared with the latest get data from the database; If this data is * newer it will be stored in the variable latest data which will be from * type @FuelEntry. If the new data is newer will be passed for printing and * it will be printed;// w w w.ja v a2s. c o m * */ private void crawlData() { try { // Create a new instance of the html unit driver // Notice that the remainder of the code relies on the interface, // not the implementation. driver = new PhantomJSDriver(); System.out.println("URL: " + Constants.BASE_URL + "/" + Constants.LOGIN_HTML); driver.get(Constants.BASE_URL + "/" + Constants.LOGIN_HTML); driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); WebElement element = driver.findElement(By.id("Field__UserLogin")); element.sendKeys(Constants.USERNAME); element = driver.findElement(By.id("Field__UserPassword")); element.sendKeys(Utility.generatePassword()); element = driver.findElement(By.xpath("(//div[@id='DivMenu']/table/tbody/tr/td)[1]")); element.click(); driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); // And now use this to visit Google // driver.get(Constants.BASE_URL + "/" + Constants.OVERVIEW_HTML); // Find the text input element by its name WebElement baseTable = driver.findElement( By.xpath("(//tr[@id='__DashBoardGroup21']/td/table[@id='__DashBoardGroup21']/tbody/tr)[3]")); List<WebElement> rawEntry = baseTable.findElements(By.tagName("td")); FuelEntry tempFuelEntry = new FuelEntry(); String[] quantityUnit = rawEntry.get(8).getText().split(" "); tempFuelEntry.setQuantity(new BigDecimal(quantityUnit[0])); tempFuelEntry.setMeasurementUnit(quantityUnit[1]); SimpleDateFormat dt = new SimpleDateFormat("dd/MM/yyyyy hh:mm:ss"); Date date = dt.parse(rawEntry.get(6).getText()); if (latestFE == null || (date.after(latestFE.getStartDate()) && tempFuelEntry.getQuantity().compareTo(BigDecimal.ZERO) > 0)) { tempFuelEntry.setDriver(rawEntry.get(2).getText()); tempFuelEntry.setVehicle(rawEntry.get(3).getText()); tempFuelEntry.setProduct(rawEntry.get(4).getText()); tempFuelEntry.setDispenzer(Integer.valueOf(rawEntry.get(5).getText())); tempFuelEntry.setStartDate(date); fuelEntryService.saveFuelEntry(tempFuelEntry); latestFE = tempFuelEntry; PrintFuelEntry pfe = new PrintFuelEntry(); pfe.printLatestEntry(); } driver.quit(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.guidewire.pstesting.policycenter.submission.gbpa.GBDriverRolesPanel.java
protected void setAccidentViolationLevel(String rowText, int columnIndex, String listItem) { if (listItem != null) { WebElement rowElement = getController().findRow(accidentsViolationsSummaryTableLocator, rowText); WebElement cellElement = rowElement.findElements(By.tagName("td")).get(columnIndex); By listLocator = By.className("x-list-plain"); getController().clickAndWait(cellElement, listLocator).type(listItem).sleep(250).pressEnter() .sleep(250);/*from w w w . ja v a 2s. c o m*/ } }
From source file:com.guidewire.pstesting.policycenter.submission.pa.DriverRolesPanel.java
protected void setAccidentViolationLevel(String rowText, int columnIndex, String listItem) { if (listItem != null) { WebElement rowElement = getController().findRow(accidentsViolationsSummaryTableLocator, rowText); WebElement cellElement = rowElement.findElements(By.tagName("td")).get(columnIndex); //Cell changes to input once list is invoked - use name attribute for each By cellInputLocator = By.name("c" + columnIndex); By listLocator = By.className("x-list-plain"); try {//from www . j av a 2s .c om getController().clickRightEdgeAndWait(cellElement, listLocator); } catch (Exception e) { getController().clickAndWaitFluently(cellElement, listLocator); } getController().setTextAndTab(cellInputLocator, listItem); } }
From source file:com.gwtplatform.carstore.cucumber.application.PageWithEditTable.java
License:Apache License
protected int getNumberOfLines(WebElement table) { return table.findElements(By.xpath("tbody[1]/tr")).size(); }
From source file:com.gwtplatform.carstore.cucumber.application.PageWithEditTable.java
License:Apache License
protected int getColumnIndex(WebElement table, String columnName) { List<WebElement> tableHeaders = table.findElements(By.cssSelector("thead th")); int index = 1; for (WebElement tableHeader : tableHeaders) { if (columnName.equals(tableHeader.getText())) { return index; }//from w w w. j a v a 2 s .co m index++; } return 0; }
From source file:com.hack23.cia.systemintegrationtest.AbstractRoleSystemTest.java
License:Apache License
/** * Click first row in grid.// w w w . j av a 2s . co m * * @param userPageVisit * the user page visit * @return the string * @throws InterruptedException * the interrupted exception */ protected final void clickFirstRowInGrid(final UserPageVisit userPageVisit) throws InterruptedException { final List<WebElement> gridRows = userPageVisit.getGridRows(); assertFalse(gridRows.isEmpty()); final WebElement choosenRow = gridRows.iterator().next(); final List<WebElement> cells = choosenRow.findElements(By.className("v-grid-cell")); final WebElement choosenCell = cells.iterator().next(); userPageVisit.performClickAction(choosenCell); }
From source file:com.hack23.cia.systemintegrationtest.UserPageVisit.java
License:Apache License
/** * Gets the menu item./* w w w .ja va2s .c o m*/ * * @param element * the element * @param level * the level * @param caption * the caption * @return the menu item */ private WebElement getMenuItem(final WebElement element, final int level, final String... caption) { final List<WebElement> findElements = element.findElements(By.className("v-menubar-menuitem-caption")); if (caption.length == level) { for (final WebElement webElement : findElements) { if (webElement.getText().contains(caption[level - 1])) { return webElement; } } } else { for (final WebElement webElement : findElements) { if (caption[level - 1].equals(webElement.getText())) { return getMenuItem(webElement, level + 1, caption); } } } final List<WebElement> findElements2 = driver.findElements(By.className("v-menubar-menuitem")); if (caption.length == level) { for (final WebElement webElement : findElements2) { if (webElement.getText().contains(caption[level - 1])) { return webElement; } } } return null; }