List of usage examples for org.openqa.selenium By tagName
public static By tagName(String tagName)
From source file:com.mto.arquillian.demo.ChromeWebDriverTest.java
License:Open Source License
@Test @RunAsClient//from www .j av a2 s . c o m @InSequence(1) public void testRegister(@ArquillianResource URL url) throws Exception { driver.navigate().to(url.toString() + "register/"); WebElement form = driver.findElement(By.tagName("form")); form.findElement(By.name("username")).sendKeys("gatein"); form.submit(); assertEquals( "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head></head><body><pre>You have registered succesfully under the name: gatein</pre></body></html>", driver.getPageSource()); }
From source file:com.mvnsnm.Tabviews.java
public void campaign() { WebElement tabhome = driver.findElement(By.xpath("//a[@id='ui-id-1']")); final String text_a = "Home"; Assert.assertEquals(text_a, tabhome.getText()); driver.findElement(By.id("ui-id-2")).click(); driver.findElement(By.xpath("//input[@id='campname']")).sendKeys("Hello Test"); WebElement select = driver.findElement(By.xpath("//select[@id='lstkeyword']")); List<WebElement> allOptions = select.findElements(By.tagName("option")); for (WebElement option : allOptions) { System.out.println(String.format("Value is: %s", option.getAttribute("value"))); String optval = option.getAttribute("value"); if (optval.equals("103")) { option.click();/*from ww w .j a va 2 s . co m*/ } } //smsmessage smssendtime smssubmit WebElement msg = driver.findElement(By.xpath("//textarea[@id='smsmessage']")); msg.sendKeys("This message bodey was set from selenium automation and should save in db"); WebElement sendtime = driver.findElement(By.xpath("//input[@id='smssendtime']")); sendtime.sendKeys("2015/02/04 10:30:00"); WebElement submit = driver.findElement(By.xpath("//input[@id='smssubmit']")); submit.click(); WebElement chweekly = driver.findElement(By.xpath("//input[@id='weekly']")); chweekly.click(); WebElement monthslct = driver.findElement(By.xpath("//select[@id='weekofmonth']")); List<WebElement> weekopt = monthslct.findElements(By.tagName("option")); for (WebElement option : weekopt) { System.out.println(String.format("Value is: %s", option.getAttribute("value"))); String optval = option.getAttribute("value"); if (optval.equals("3")) { option.click(); } } //createmoremsg WebElement weekmsg = driver.findElement(By.xpath("//textarea[@id='createmoremsg']")); weekmsg.sendKeys("This message bodey was set for weekly report and can be saved in db"); //moremsgsave WebElement more_msg = driver.findElement(By.xpath("//input[@id='moremsgsave']")); more_msg.click(); chweekly.click(); WebElement monthly = driver.findElement(By.xpath("//input[@id='monthly']")); monthly.click(); WebElement monthofyear = driver.findElement(By.xpath("//select[@id='monthofyear']")); List<WebElement> monthopt = monthofyear.findElements(By.tagName("option")); for (WebElement option : monthopt) { System.out.println(String.format("Value is: %s", option.getAttribute("value"))); String optval = option.getAttribute("value"); if (optval.equals("7")) { option.click(); } } //createmoremsg WebElement monthlymsg = driver.findElement(By.xpath("//textarea[@id='monthlymsgmore']")); monthlymsg.sendKeys("This message bodey was set for weekly report and can be saved in db"); //moremsgsave WebElement monthlymsgsave = driver.findElement(By.xpath("//input[@id='monthlymsgsave']")); monthlymsgsave.click(); monthly.click(); }
From source file:com.mycompany.selenium.SeleniumTests.java
@Test public void test1() throws Exception { (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(5)); return true; });/*from www . j ava2 s.com*/ }
From source file:com.mycompany.selenium.SeleniumTests.java
@Test public void test2() throws Exception { WebElement element = driver.findElement(By.id("filter")); element.clear();/* ww w. ja v a 2 s .c o m*/ 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:com.mycompany.selenium.SeleniumTests.java
@Test public void test3() throws Exception { WebElement element = driver.findElement(By.id("filter")); element.sendKeys(Keys.BACK_SPACE);/* w w w . ja va2s. c om*/ WebElement table = driver.findElement(By.tagName("tbody")); List<WebElement> rows = table.findElements(By.tagName("tr")); Assert.assertThat(rows.size(), is(5)); }
From source file:com.mycompany.selenium.SeleniumTests.java
@Test public void test4() throws Exception { WebElement sort = driver.findElement(By.id("h_year")); sort.click();//from w ww. ja va2 s. c o m WebElement table = driver.findElement(By.tagName("tbody")); List<WebElement> sortedRows = table.findElements(By.tagName("tr")); String firstRow = sortedRows.get(0).findElements(By.tagName("td")).get(0).getText(); String lastRow = sortedRows.get(4).findElements(By.tagName("td")).get(0).getText(); Assert.assertThat(firstRow, is("938")); Assert.assertThat(lastRow, is("940")); }
From source file:com.mycompany.selenium.SeleniumTests.java
@Test public void test5() throws Exception { WebElement editButton = null;//from w w w. j ava2s .c o 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 ww w .j a v a2 s . com*/ }
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"); }//from w w w .java 2 s . com System.out.println(); } }
From source file:com.nosoftskills.travianbot.page.AlliancePlayers.java
License:Apache License
private String getPlayerName(WebElement webElement) { return webElement.findElement(By.tagName("a")).getText(); }