List of usage examples for org.openqa.selenium WebElement findElements
@Override List<WebElement> findElements(By by);
From source file:CarTest1.java
@Test public void test7() throws Exception { WebElement newCar = driver.findElement(By.id("new")); newCar.click();//from w w w .ja v a 2s . c om WebElement year = driver.findElement(By.name("year")); WebElement reg = driver.findElement(By.name("registered")); WebElement make = driver.findElement(By.name("make")); WebElement model = driver.findElement(By.name("model")); WebElement desc = driver.findElement(By.name("description")); WebElement price = driver.findElement(By.name("price")); WebElement submit = driver.findElement(By.id("save")); year.sendKeys("2008"); reg.sendKeys("2002-5-5"); make.sendKeys("Kia"); model.sendKeys("Rio"); desc.sendKeys("As new"); price.sendKeys("31000"); submit.click(); (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> { WebElement e = d.findElement(By.tagName("tbody")); List<WebElement> rows = e.findElements(By.tagName("tr")); Assert.assertThat(rows.size(), is(6)); return true; }); }
From source file:testTheClient.java
@Test public void domLoaded5RowsinTbody() { WebElement tableBody = (new WebDriverWait(driver, WAIT_MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.tagName("tbody")); });//from w w w . ja va 2 s . c o m Assert.assertThat(tableBody.findElements(By.tagName("tr")).size(), is(5)); }
From source file:testTheClient.java
@Test public void lookUp2002() throws Exception { WebElement element = (new WebDriverWait(driver, WAIT_MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return driver.findElement(By.xpath("//*[@id=\"filter\"]")); });/*from w w w.ja v a 2 s . c o m*/ element.clear(); element.sendKeys("2002"); WebElement table = driver.findElement(By.tagName("tbody")); List<WebElement> rows = table.findElements(By.tagName("tr")); Assert.assertThat(rows.size(), is(2)); }
From source file:testTheClient.java
@Test public void removeFilterTest() throws Exception { WebElement element = driver.findElement(By.id("filter")); element.sendKeys(Keys.BACK_SPACE);/*from w w w . j a v a2 s . c o m*/ WebElement tableBody = (new WebDriverWait(driver, WAIT_MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.tagName("tbody")); }); List<WebElement> rows = tableBody.findElements(By.tagName("tr")); Assert.assertThat(rows.size(), is(5)); }
From source file:testTheClient.java
@Test public void sortByYear() { WebElement sort = (new WebDriverWait(driver, WAIT_MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return driver.findElement(By.xpath("//*[@id=\"h_year\"]")); });//from ww w . j av a2s.c om sort.click(); WebElement table = driver.findElement(By.tagName("tbody")); List<WebElement> sortedRows = table.findElements(By.tagName("tr")); Assert.assertThat(sortedRows.get(0).findElements(By.tagName("td")).get(0).getText(), is("938")); Assert.assertThat(sortedRows.get(4).findElements(By.tagName("td")).get(0).getText(), is("940")); }
From source file:testTheClient.java
@Test public void verifyAlterations() throws Exception { WebElement editButton = null; List<WebElement> rows = (new WebDriverWait(driver, WAIT_MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.tagName("tbody")); }).findElements(By.tagName("tr")); ;/*from w w w . jav a 2 s.co m*/ 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); //click the edit button editButton.click(); //clear description field and type coolscars WebElement element = driver.findElement(By.id("description")); element.clear(); element.sendKeys("cool cars"); driver.findElement(By.xpath("//*[@id=\"save\"]")).click(); List<WebElement> updatedRows = (new WebDriverWait(driver, WAIT_MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.tagName("tbody")); }).findElements(By.tagName("tr")); ; String newDescr = null; for (int i = 0; i < updatedRows.size(); i++) { if (updatedRows.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) { newDescr = updatedRows.get(i).findElements(By.tagName("td")).get(5).getText(); break; } } assertThat(newDescr, is("cool cars")); }
From source file:NewCarTest.java
private String getCarFieldValue(WebElement rowElement, int fieldNo) { return rowElement.findElements(By.tagName("td")).get(fieldNo).getText(); }
From source file:NewCarTest.java
private List<WebElement> getRowsOfCars() { WebElement table = driver.findElement(By.id("tbodycars")); return table.findElements(By.tagName("tr")); }
From source file:ProveedorTest.java
@Test public void testCreateProveedor() throws Exception { /**//from w w w. j ava 2 s . c o m * Comando que realiza click sobre el boton "create" del toolbar. La * funcin 'find' encuentra el control y posteriormente hace clic en el * mismo. La forma en la que se busca el control es utilizando * expresiones xPath ya que los id de los mismos nunca son iguales (se * generan con junto con el valor de componentId que vara). */ driver.findElement(By.xpath("//button[contains(@id,'createButton')]")).click(); /** * Comando que duerme el Thread del test por 2 segundos para dejar que * el efecto 'slide down' de backbone abra el formulario de createSport. */ Thread.sleep(2000); String name = "Nombresito"; String email = "test@test.com"; String telefono = "1231235"; String direccion = "carrera 1 con calle 2"; String observaciones = "jejejejejeje"; /** * Comando que busca el elemento 'name' en el html actual. * Posteriormente limpia su contenido (comando clean). */ driver.findElement(By.id("name")).clear(); /** * Comando que simula la escritura de un valor en el elemento(sendKeys) * con el String de parmetro sobre // el elemento encontrado. */ driver.findElement(By.id("name")).sendKeys(name); //Comandos para llenar el campo email driver.findElement(By.id("email")).clear(); driver.findElement(By.id("email")).sendKeys(email); /** * Comandos para llenar el campo telefono */ driver.findElement(By.id("telefono")).clear(); driver.findElement(By.id("telefono")).sendKeys(telefono); /** * Comandos para llenar el campo direccion */ driver.findElement(By.id("direccion")).clear(); driver.findElement(By.id("direccion")).sendKeys(direccion); /** * Comandos para llenar el campo observaciones */ driver.findElement(By.id("observaciones")).clear(); driver.findElement(By.id("observaciones")).sendKeys(observaciones); /** * Comando que encuentra y hace clic sobre el boton "Save" del toolbar * (una vez mas encontrado por una expresin Xpath) */ driver.findElement(By.xpath("//button[contains(@id,'saveButton')]")).click(); /** * Comando que duerme el thread para esperar el efecto de slide down que * abre la lista */ Thread.sleep(2000); /** * Comando que obtiene el div azul de creacin exitosa. Si se obtiene, * la prueba va bien, si no, saldr un error y la prueba quedar como * fllida. */ WebElement dialog = driver.findElement(By.xpath("//div[contains(@style,'display: block;')]")); /** * Comando que obtiene la tabla con el elemento que se cre * anteriormente. */ List<WebElement> table = driver .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr")); boolean sucess = false; /** * Se itera sobre los elementos de la tabla para ver si el nuevo * elemento creado est en la lista */ for (WebElement webElement : table) { List<WebElement> elems = webElement.findElements(By.xpath("td")); if (elems.get(0).getText().equals(name) && elems.get(1).getText().equals(email) && elems.get(2).getText().equals(telefono) && elems.get(3).getText().equals(direccion) && elems.get(4).getText().equals(observaciones)) { /** * si se encuentra la fila, la variable 'fail' pasa a true, * indicando que el elemento creado esta en la lista. */ sucess = true; } } /** * la prueba es exitosa si se encontr el dialogo de creacin exitosa y * el nuevo elemento est en la lista. */ assertTrue(dialog != null && sucess); }
From source file:ProveedorTest.java
@Test public void testUpdateProveedor() throws Exception { String name = "Un nombre ahi"; String email = "prueba@prueba.com.co"; String telefono = "9999999"; String direccion = "diagonal 5 con calle 6"; String observaciones = "hohohoo"; /**/* ww w.j av a 2s . co m*/ * Se hace clic en el vinculo "Edit" del primer elemento de la lista de * sports */ driver.findElement(By.linkText("Editar")).click(); Thread.sleep(2000); /** * Se realiza el mismo proceso de diligenciamento de los campos con los * cambios */ driver.findElement(By.id("name")).clear(); driver.findElement(By.id("name")).sendKeys(name); driver.findElement(By.id("email")).clear(); driver.findElement(By.id("email")).sendKeys(email); driver.findElement(By.id("telefono")).clear(); driver.findElement(By.id("telefono")).sendKeys(telefono); driver.findElement(By.id("direccion")).clear(); driver.findElement(By.id("direccion")).sendKeys(direccion); driver.findElement(By.id("observaciones")).clear(); driver.findElement(By.id("observaciones")).sendKeys(observaciones); driver.findElement(By.xpath("//button[contains(@id,'saveButton')]")).click(); Thread.sleep(2000); /** * Se verifica que en la lista de respuesta hallan aparecido los cambios * en el elemento y tambin el mensaje de edicin exitosa. */ WebElement dialog = driver.findElement(By.xpath("//div[contains(@style,'display: block;')]")); List<WebElement> table = driver .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr")); boolean fail = false; for (WebElement webElement : table) { List<WebElement> elems = webElement.findElements(By.xpath("td")); if (elems.get(0).getText().equals(name) && elems.get(1).getText().equals(email) && elems.get(2).getText().equals(telefono) && elems.get(3).getText().equals(direccion) && elems.get(4).getText().equals(observaciones)) { fail = true; } } assertTrue(dialog != null && fail); }