List of usage examples for org.openqa.selenium WebElement findElements
@Override List<WebElement> findElements(By by);
From source file:de.learnlib.alex.data.entities.actions.web.SelectActionTest.java
License:Apache License
@Test public void shouldReturnOkIfValueWasSelectedByValue() { WebElement selectElement = mock(WebElement.class); given(webSiteConnector.getElement(node)).willReturn(selectElement); given(selectElement.getTagName()).willReturn("select"); WebElement itemElement = mock(WebElement.class); List<WebElement> itemElements = new ArrayList<>(); itemElements.add(itemElement);/*from ww w. j a v a2 s .co m*/ given(selectElement.findElements(By.xpath(".//option[@value = \"Lorem Ipsum\"]"))).willReturn(itemElements); s.setSelectBy(SelectAction.SelectByType.VALUE); ExecuteResult result = s.executeAction(connectors); assertTrue(result.isSuccess()); verify(itemElement).click(); }
From source file:de.learnlib.alex.data.entities.actions.web.SelectActionTest.java
License:Apache License
@Test public void shouldReturnOkIfValueWasSelectedByText() { WebElement selectElement = mock(WebElement.class); given(webSiteConnector.getElement(node)).willReturn(selectElement); given(selectElement.getTagName()).willReturn("select"); WebElement itemElement = mock(WebElement.class); List<WebElement> itemElements = new ArrayList<>(); itemElements.add(itemElement);//w w w. j av a 2 s . c o m given(selectElement.findElements(By.xpath(".//option[normalize-space(.) = \"Lorem Ipsum\"]"))) .willReturn(itemElements); s.setSelectBy(SelectAction.SelectByType.TEXT); ExecuteResult result = s.executeAction(connectors); assertTrue(result.isSuccess()); verify(itemElement).click(); }
From source file:de.learnlib.alex.data.entities.actions.web.SelectActionTest.java
License:Apache License
@Test public void shouldReturnOkIfValueWasSelectedByIndex() { WebElement selectElement = mock(WebElement.class); given(webSiteConnector.getElement(node)).willReturn(selectElement); given(selectElement.getTagName()).willReturn("select"); List<WebElement> itemElements = new ArrayList<>(); given(selectElement.findElements(By.tagName("option"))).willReturn(itemElements); WebElement itemElement = mock(WebElement.class); itemElements.add(itemElement);//from w ww.j a va 2 s.c o m given(itemElement.getAttribute("index")).willReturn("0"); s.setValue("0"); s.setSelectBy(SelectAction.SelectByType.INDEX); ExecuteResult result = s.executeAction(connectors); assertTrue(result.isSuccess()); verify(itemElement).click(); }
From source file:de.meethub.adapters.xing.XingAdapterServlet.java
License:Open Source License
private Date extractStartTime(final WebElement eventElement) throws ParseException, ServletException { for (final WebElement meta : eventElement.findElements(By.tagName("meta"))) { if ("startDate".equals(meta.getAttribute("itemprop"))) { final SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX"); return f.parse(meta.getAttribute("content")); }/*www .j a va2 s. c o m*/ } throw new ServletException("could not extract date from " + eventElement); }
From source file:de.tklerx.run.ResEntries.java
License:Open Source License
private static List<Player> parsePlayerPage(List<String> otherPlayerPages) throws ParseException, InterruptedException { List<Player> result = new ArrayList<>(); WebElement table = driver.findElement(By.className("result-set")); List<WebElement> rows = table.findElements(By.xpath("//tbody/tr")); System.out.println("NUMBER OF ROWS IN THIS TABLE = " + rows.size()); for (WebElement trElement : rows) { List<WebElement> td_collection = trElement.findElements(By.xpath("td")); System.out.println("NUMBER OF COLUMNS=" + td_collection.size()); if (td_collection.size() == 3 && otherPlayerPages != null && otherPlayerPages.isEmpty()) { // found the header // parse the links for the other pages List<WebElement> otherPages = td_collection.get(2).findElements(By.xpath("a")); for (WebElement e : otherPages) { otherPlayerPages.add(e.getAttribute("href")); }/* w ww.j ava 2s .c o m*/ } else if (td_collection.size() == 7) { // its a player entry String playerName = td_collection.get(0).getText(); WebElement teamLink = td_collection.get(1); String history = td_collection.get(2).getText(); if (!history.isEmpty()) { continue; } String date = td_collection.get(5).getText(); String team = td_collection.get(6).getText(); Player p = new Player(playerName, date, team, history, teamLink.findElement(By.xpath("a")).getAttribute("href")); result.add(p); } } for (Player p : result) { processPlayer(p); } return result; }
From source file:de.tntinteractive.portalsammler.sources.HanVBSourceV1.java
License:Open Source License
@Override public Pair<Integer, Integer> poll(final SourceSettings settings, final UserInteraction gui, final SecureStore store) throws Exception { final WebDriver driver = this .createDriver("https://www.hannoversche-volksbank.de/ptlweb/WebPortal?bankid=0744"); final WebElement userField = driver.findElement(By.id("vrkennungalias")); userField.sendKeys(settings.get(USER, gui)); final WebElement passwordField = driver.findElement(By.id("pin")); passwordField.sendKeys(settings.get(PASSWORD, gui)); passwordField.submit();/*from w w w.ja va 2s . c o m*/ waitForPresence(driver, By.linkText("Postkorb")); int newDocs = 0; int knownDocs = 0; try { clickLink(driver, "Postkorb"); waitForPresence(driver, By.name("confirmDeleteMultiMessage")); final WebElement form = driver.findElement(By.name("confirmDeleteMultiMessage")); final WebElement tbody = form.findElement(By.tagName("tbody")); final List<String> links = new ArrayList<String>(); for (final WebElement tr : tbody.findElements(By.tagName("tr"))) { final List<WebElement> tds = tr.findElements(By.tagName("td")); final WebElement link = tds.get(2).findElement(By.tagName("a")); links.add(link.getAttribute("href")); } for (final String link : links) { driver.get(link); final DocumentInfo info = DocumentInfo.create(this.getId(), DocumentFormat.TEXT); final StringBuilder content = new StringBuilder(); driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); final WebElement fieldset = driver.findElement(By.tagName("fieldset")); for (final WebElement div : fieldset.findElements(By.tagName("div"))) { if (this.isLabeled(div, "Eingang")) { info.setDate(this.parseTimestamp(div.findElement(By.className("gad-field-box")).getText())); } else if (this.isLabeled(div, "Betreff")) { final WebElement data = div.findElement(By.className("gad-field-box")); info.addKeywords(data.findElement(By.tagName("span")).getAttribute("title")); } else if (this.isNotLabeled(div)) { content.append(div.getText()); } } driver.manage().timeouts().implicitlyWait(WAIT_TIME, TimeUnit.SECONDS); if (!store.containsDocument(info)) { store.storeDocument(info, content.toString().getBytes("UTF-8")); newDocs++; } else { knownDocs++; } } } finally { clickLink(driver, "Logout"); } return Pair.of(newDocs, knownDocs); }
From source file:de.tntinteractive.portalsammler.sources.HanVBSourceV1.java
License:Open Source License
private boolean isLabeled(final WebElement div, final String string) { for (final WebElement label : div.findElements(By.tagName("label"))) { if (label.getText().contains(string)) { return true; }// w ww.j a v a 2 s. co m } return false; }
From source file:de.tntinteractive.portalsammler.sources.IngDibaSourceV1.java
License:Open Source License
@Override public Pair<Integer, Integer> poll(final SourceSettings settings, final UserInteraction gui, final SecureStore store) throws Exception { final WebDriver driver = this.createDriver("https://banking.ing-diba.de/app/login"); final WebElement userField = driver.findElement(By.name("view:kontonummer:border:border_body:kontonummer")); userField.sendKeys(settings.get(USER, gui)); final WebElement passwordField = driver.findElement(By.name("view:pin:border:border_body:pin")); passwordField.sendKeys(settings.get(PASSWORD, gui)); passwordField.submit();/*from w ww . jav a 2 s . c o m*/ waitForPresence(driver, By.className("dbkpBoard")); final List<Integer> missingValues = new ArrayList<Integer>(); for (final WebElement possibleKeyInput : driver.findElements(By.tagName("input"))) { final String missingValuePrefix = "view:key:border:border_body:key:dbkpDisplayDiv:values:"; final String name = possibleKeyInput.getAttribute("name"); if (startsWith(name, missingValuePrefix)) { final String s = name.substring(missingValuePrefix.length(), missingValuePrefix.length() + 1); missingValues.add(Integer.parseInt(s)); } } final String code = settings.get(CODE, gui); for (final Integer missing : missingValues) { final String number = Character.toString(code.charAt(missing)); clickButton(driver, number); } clickButton(driver, "Anmelden"); waitForPresence(driver, By.partialLinkText("Post-Box")); clickLink(driver, "Post-Box"); (new WebDriverWait(driver, WAIT_TIME)) .until(ExpectedConditions.invisibilityOfElementLocated(By.id("busy"))); int newDocs = 0; int knownDocs = 0; try { final FileDownloader d = new FileDownloader(driver); for (final WebElement row : driver.findElements(By.tagName("tbody"))) { final DocumentInfo metadata = DocumentInfo.create(this.getId(), DocumentFormat.PDF); for (final WebElement cell : row.findElements(By.tagName("td"))) { final String text = cell.getText(); if (this.isDate(text)) { metadata.setDate(parseDate(text)); } else { metadata.addKeywords(text); } } if (!store.containsDocument(metadata)) { final WebElement link = row.findElement(By.tagName("a")); final byte[] file = d.downloadFile(link); store.storeDocument(metadata, file); newDocs++; } else { knownDocs++; } } } finally { clickLink(driver, "Log-out"); } return Pair.of(newDocs, knownDocs); }
From source file:de.tntinteractive.portalsammler.sources.MlpSourceV1.java
License:Open Source License
@Override public Pair<Integer, Integer> poll(final SourceSettings settings, final UserInteraction gui, final SecureStore store) throws Exception { final WebDriver driver = this .createDriver("https://financepilot-pe.mlp.de/p04pepe/entry?rzid=XC&rzbk=0752"); final WebElement userField = driver.findElement(By.id("txtBenutzerkennung")); userField.sendKeys(settings.get(USER, gui)); final WebElement passwordField = driver.findElement(By.className("XPassword")); passwordField.sendKeys(settings.get(PASSWORD, gui)); passwordField.submit();// www .j a v a 2 s . c om int newDocs = 0; int knownDocs = 0; try { clickLink(driver, "Postfach"); clickButton(driver, "Dokumente anzeigen"); final WebElement table = driver.findElement(By.id("tblKontoauszuege")); final WebElement tBody = table.findElement(By.xpath("tbody")); final FileDownloader d = new FileDownloader(driver); for (final WebElement tr : tBody.findElements(By.tagName("tr"))) { final List<WebElement> tds = tr.findElements(By.tagName("td")); final DocumentInfo doc = DocumentInfo.create(this.getId(), DocumentFormat.PDF); if (tds.get(2).getText().isEmpty()) { continue; } doc.addKeywords(tds.get(0).getText()); doc.addKeywords(tds.get(1).getText()); doc.setDate(parseDate(tds.get(2).getText())); if (!store.containsDocument(doc)) { final WebElement link = tds.get(0).findElement(By.tagName("a")); final byte[] file = d.downloadFile(link); store.storeDocument(doc, file); newDocs++; } else { knownDocs++; } } } finally { clickButton(driver, "Abmelden"); } return Pair.of(newDocs, knownDocs); }
From source file:demo.seleniumtest.DemoTest.java
@Test public void test4() { //Press the edit button for the car with the id 938. Change the Description to "Cool car", and save changes. //Verify that the row for car with id 938 now contains "Cool car" in the Description column final String expectedDescription = "Cool car"; new WebDriverWait(driver, waitTime).until(new Function<WebDriver, Object>() { public Boolean apply(WebDriver wd) { wd.findElement(By.id("tbodycars")); return true; }// w ww . j av a 2 s .co m }); List<WebElement> rows = driver.findElement(By.id("tbodycars")).findElements(By.tagName("tr")); for (WebElement row : rows) { List<WebElement> columns = row.findElements(By.tagName("td")); if (columns.get(0).getText().equals("938")) { columns.get(columns.size() - 1) // Get last td in that tr - which should be: "action"/description .findElements(By.tagName("a")).get(0) // First a tag --> description, not delete .click(); WebElement descriptionInput = driver.findElement(By.id("description")); descriptionInput.clear(); descriptionInput.sendKeys("Cool car"); driver.findElement(By.id("save")).click(); String actualDescription = columns.get(5).getText(); assertThat(actualDescription, is(expectedDescription)); break; } } }