List of usage examples for org.openqa.selenium WebElement findElements
@Override List<WebElement> findElements(By by);
From source file:com.mycompany.selenium.SeleniumTests.java
@Test public void test5() throws Exception { WebElement editButton = null;//w ww.j a va 2s .co m driver.get("http://localhost:3000"); WebDriverWait wait = new WebDriverWait(driver, WAIT_MAX); wait.until(ExpectedConditions.visibilityOfElementLocated((By.tagName("thead")))); driver.switchTo().parentFrame(); WebElement table = driver.findElement(By.tagName("tbody")); List<WebElement> rows = table.findElements(By.tagName("tr")); //loop through rows to find car with id "938" for (int i = 0; i < rows.size(); i++) { if (rows.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) { editButton = rows.get(i); break; } } editButton = editButton.findElements(By.tagName("td")).get(7).findElements(By.tagName("a")).get(0); editButton.click(); driver.findElement(By.id("description")).clear(); wait.until(ExpectedConditions.visibilityOfElementLocated((By.id("description")))); driver.findElement(By.id("description")).sendKeys("cool cars"); driver.findElement(By.id("save")).click(); (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> { WebElement updatedTable = d.findElement(By.tagName("tbody")); List<WebElement> updatedRows = updatedTable.findElements(By.tagName("tr")); String editedRow = null; //loop through rows to find car with id "938" for (int i = 0; i < updatedRows.size(); i++) { if (updatedRows.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) { editedRow = updatedRows.get(i).findElements(By.tagName("td")).get(5).getText(); break; } } assertThat(editedRow, is("cool cars")); return true; }); }
From source file:com.mycompany.selenium.SeleniumTests.java
@Test //Click the new Car Button, and add the following values for a new car public void test7() throws Exception { WebDriverWait wait = new WebDriverWait(driver, WAIT_MAX); wait.until(ExpectedConditions.visibilityOfElementLocated((By.id("new")))); driver.findElement(By.id("new")).click(); driver.findElement(By.id("year")).sendKeys("2008"); driver.findElement(By.id("registered")).sendKeys("2002-5-5"); driver.findElement(By.id("make")).sendKeys("Kia"); driver.findElement(By.id("model")).sendKeys("Rio"); driver.findElement(By.id("description")).sendKeys("As new"); driver.findElement(By.id("price")).sendKeys("31000"); //save the new car driver.findElement(By.id("save")).click(); (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> { WebElement updatedTable = d.findElement(By.tagName("tbody")); List<WebElement> updatedRows = updatedTable.findElements(By.tagName("tr")); //row count should be 6 assertThat(updatedRows.size(), is(6)); //new car should be on row 6, check year assertThat(updatedRows.get(5).findElements(By.tagName("td")).get(1).getText(), is("2008")); //model is Rio assertThat(updatedRows.get(5).findElements(By.tagName("td")).get(4).getText(), is("Rio")); return true; });//from w ww. j a va2 s . c om }
From source file:com.nabla.project.fronter.selenium.tests.helper.SeleniumHelper.java
License:Open Source License
public static void testWebTable(final WebElement simpleTable, final int expectedRows) { // Get all rows final List<WebElement> rows = simpleTable.findElements(By.tagName("tr")); Assert.assertEquals(expectedRows, rows.size()); // Print data from each row for (final WebElement row : rows) { final List<WebElement> cols = row.findElements(By.tagName("td")); for (final WebElement col : cols) { System.out.print(col.getText() + "\t"); }/* ww w . j a va2 s. c o m*/ System.out.println(); } }
From source file:com.nosoftskills.travianbot.page.FarmList.java
License:Apache License
private static void selectGreen(WebElement webElement) { webElement.findElements(By.className("slotRow")).stream().filter(FarmList::isGreenFlag) .forEach(FarmList::select);/*from ww w . jav a 2s . c o m*/ }
From source file:com.nosoftskills.travianbot.page.Home.java
License:Apache License
private IncomingAttack attachAttackDetails(IncomingAttack incomingAttack) { webDriver.get(incomingAttack.getVillageLink()); WebElement movementsTable = webDriver.findElement(By.id("movements")); WebElement attackRow = movementsTable.findElements(By.tagName("tr")).stream() .filter(webElement -> !webElement.findElements(By.cssSelector(".att1")).isEmpty() || !webElement.findElements(By.cssSelector(".att3")).isEmpty()) .findFirst().orElseThrow(IllegalArgumentException::new); incomingAttack.setInTime(attackRow.findElement(By.className("timer")).getText()); WebElement attackDescription = attackRow.findElement(By.cssSelector(".a1")); if (attackDescription == null) { attackDescription = attackRow.findElement(By.cssSelector(".a1")); }//from w w w . j a v a 2s . c o m incomingAttack.setNumberOfAttacks(attackDescription.getText().split(" ")[0]); return incomingAttack; }
From source file:com.nowsprinting.hellotesting.appiumtest.appium.page.DetailPage.java
License:Apache License
/** * NumberPicker?1?????/*from www . ja v a2 s . com*/ * ?????????????? */ private void incrementCurrentAge(WebElement numberPicker) throws Exception { int currentAge = getCurrentAge(numberPicker); if (currentAge == AGE_MAX) { return; } WebElement incButton; if (currentAge == AGE_MIN) { // ???????????????? // ?????? incButton = numberPicker.findElement(By.className(WIDGET_BUTTON)); } else { // ???????????????? // ??????2???(index?1)????? incButton = numberPicker.findElements(By.className(WIDGET_BUTTON)).get(1); } incButton.click(); if (getCurrentAge(numberPicker) == currentAge + 1) { // click()??1?????return? return; } // click()???????tap()?Android 5.0?? // ??????????? TimeUnit.SECONDS.sleep(1); ((MobileElement) incButton).tap(1, 10); waitUntilAgeToBe(numberPicker, currentAge + 1); }
From source file:com.nowsprinting.hellotesting.appiumtest.appium.page.DetailPage.java
License:Apache License
/** * NumberPicker?1??????//from w w w. j a v a2s. com * ??????????????? */ private void decrementCurrentAge(WebElement numberPicker) throws Exception { int currentAge = getCurrentAge(numberPicker); if (currentAge == AGE_MIN) { return; } WebElement decButton; if (currentAge == AGE_MAX) { // ??????????????? // ?????? decButton = numberPicker.findElement(By.className(WIDGET_BUTTON)); } else { // ???????????????? // ??????1???(index?0)????? decButton = numberPicker.findElements(By.className(WIDGET_BUTTON)).get(0); } decButton.click(); if (getCurrentAge(numberPicker) == currentAge - 1) { // click()??1?????return? return; } // click()???????tap()?Android 5.0?? // ??????????? TimeUnit.SECONDS.sleep(1); ((MobileElement) decButton).tap(1, 10); waitUntilAgeToBe(numberPicker, currentAge - 1); }
From source file:com.osbitools.ws.pd.xui.PageDesignerGuiWebTest.java
License:LGPL
private void checkPanelWidgetCnt(WebElement ctx, int pcnt, int wcnt) { // Check for number of panels List<WebElement> panels = ctx.findElements(By.cssSelector("td.comp-panel")); assertEquals("Number of panel(s) doesn't match", pcnt, panels.size()); // Check for total number of web widgets on all panel List<WebElement> widgets = ctx.findElements(By.className("wwg")); assertEquals("Number of widget(s) doesn't match", wcnt, widgets.size()); // Check property tab for container }
From source file:com.osbitools.ws.shared.prj.xui.GenericPrjMgrGuiWebTest.java
License:LGPL
private void ctxMenuListClick(WebElement ctx, int idx) { List<WebElement> menu = ctx.findElements(By.tagName("a")); menu.get(idx).click();//from w w w .ja v a 2 s . co m }
From source file:com.osbitools.ws.shared.prj.xui.GenericPrjMgrGuiWebTest.java
License:LGPL
/** * Check project widget with/without first entity created * @param lang Test language/*from w w w. java 2 s .com*/ * @param pname Project name * @param fent True when first entity created */ private void checkProjectWidget(String lang, String pname, boolean fent) { checkLangElementById(lang, "LL_SELECT_PROJECT"); WebElement psel = driver.findElement(By.id("project_sel")); assertEquals(pname, psel.getAttribute("value")); List<WebElement> ops = psel.findElements(By.tagName("option")); assertEquals(1, ops.size()); assertEquals(pname, ops.get(0).getText()); checkLangElementById(lang, "LL_NEW"); checkLangElementById(lang, "LL_RENAME"); checkLangElementById(lang, "LL_DELETE"); checkLangElementById(lang, "LL_GIT_PUSH"); checkLangElementById(lang, "LL_LOGOUT"); // Look for new button WebElement btn = driver.findElement(By.className("node-new-btn")); assertNotNull("New Button is not found", btn); WebElement img = btn.findElement(By.tagName("img")); assertNotNull(img); assertEquals("http://localhost:8090/web_test/fr/" + "modules/prj/images/new_entity.png", img.getAttribute("src")); WebElement bname = btn.findElement(By.tagName("a")); assertNotNull(bname); assertEquals(getLabelText(lang, "LL_NEW"), bname.getText()); assertEquals("pointer", bname.getCssValue("cursor")); // Check list of component groups and icons checkComponentList(lang, fent); // Check project controls disabled checkElementVisible("ws_list", fent); checkElementVisible("entity_ctx_ctrl", fent); if (fent) { checkDataSourceList(lang); checkDbConnList(lang); } }