List of usage examples for org.openqa.selenium WebElement getText
String getText();
From source file:com.example.selenium.find.elements.FindElementXPath.java
@Test public void getElementwithText() { driver.get("http://localhost:8080/WebApplication/pages/tables.html"); WebElement element = driver.findElement(By.xpath("//td[.='Firefox 3.0']")); System.out.println("Elements matching Text =" + element.getText()); }
From source file:com.example.selenium.Table.java
public boolean validateTable() { boolean flag = true; List<WebElement> tablesRows; try {/*from ww w . j ava2s. c o m*/ Select selectRows = new Select(tableDropDown); tableDropDown.click(); Thread.sleep(2000); selectRows.selectByValue("10"); tableDropDown.click(); WebDriverWait wait = new WebDriverWait(selenium, 10); tablesRows = wait.until(ExpectedConditions .numberOfElementsToBe(By.xpath("//table[@id='dataTables-example']/tbody/tr"), 10)); if (tablesRows.size() != 10) { flag = false; } Thread.sleep(1000); selectRows.selectByValue("25"); tableDropDown.click(); tablesRows = wait.until(ExpectedConditions .numberOfElementsToBe(By.xpath("//table[@id='dataTables-example']/tbody/tr"), 25)); if (tablesRows.size() != 25) { flag = false; } Thread.sleep(1000); selectRows.selectByValue("50"); tableDropDown.click(); tablesRows = wait.until(ExpectedConditions .numberOfElementsToBe(By.xpath("//table[@id='dataTables-example']/tbody/tr"), 50)); if (tablesRows.size() != 50) { flag = false; } Thread.sleep(2000); tableSearch.sendKeys("Presto"); Thread.sleep(1000); WebElement element = new WebDriverWait(selenium, 5).until(new ExpectedCondition<WebElement>() { public WebElement apply(WebDriver d) { return d.findElement(By.xpath("//td[contains(text(),'Presto')]")); } }); if (!element.getText().equals("Presto")) { flag = false; } return flag; } catch (InterruptedException ex) { Logger.getLogger(Table.class.getName()).log(Level.SEVERE, null, ex); } return flag; }
From source file:com.example.todo.selenium.todo.TodoTest.java
License:Apache License
/** * Asserts that one todo is created./*from w ww.j a v a2 s .co m*/ */ @Test public void testCreate() throws IOException { inputFieldAccessor.overrideValue(By.id("todoTitle"), "todoThings1", driver); driver.findElement(By.xpath("//form[@action='/" + contextName + "/todo/create']/button")).click(); ; WebElement todoElement = driver.findElement(By.xpath("//div[@id='todoList']/ul/li")); assertThat(driver.findElement(By.xpath("//div[@class='alert alert-success']/ul/li")).getText(), is("Created successfully!")); assertThat(todoElement.getText(), is(containsString("todoThings1"))); todoElement.findElement(By.xpath("//form[@action='/" + contextName + "/todo/delete']/button")).click(); }
From source file:com.fmb.common.BrowserEmulator.java
License:Apache License
/** * Return text from specified web element. * @param xpath/*www .jav a 2s . c o m*/ * @return */ public String getText(String xpath) { WebElement element = this.getBrowserCore().findElement(By.xpath(xpath)); return element.getText(); }
From source file:com.formkiq.web.EquifaxIntegrationTest.java
License:Apache License
/** * test empty equifax.//from w ww.jav a 2 s.c o m * * @throws Exception Exception */ @Test public void testEmptyTable() throws Exception { // given // when login(getDefaultEmail()); getDriver().navigate().to(getDefaultHostAndPort() + "/admin/equifax"); // then assertEquals("FormKiQ Server - Equifax", getTitle()); waitUntil(new Predicate<WebDriver>() { @Override public boolean apply(final WebDriver d) { WebElement e = findElements(By.xpath("//table[@id='results']")).get(0); return e.getText().contains("No Equifax Credit Check(s)"); } }); }
From source file:com.formkiq.web.EquifaxIntegrationTest.java
License:Apache License
/** * test non empty equifax.//from w w w. ja va 2s.c o m * * @throws Exception Exception */ @Test public void testEquifaxData() throws Exception { // given Authentication auth = new OAuth2Authentication(null, new UsernamePasswordAuthenticationToken("test", "test")); SecurityContextHolder.getContext().setAuthentication(auth); FormJSON form = this.ob.getEquifaxcc(this.jsonService); findValueByKey(form, "firstname").get().setValue("John"); findValueByKey(form, "familyname").get().setValue("Smith"); findValueByKey(form, "birthdate").get().setValue(this.jsonService.dateToString(new Date())); this.equifaxHandler.handleEvent(form, "any"); // when login(getDefaultEmail()); getDriver().navigate().to(getDefaultHostAndPort() + "/admin/equifax"); // then assertEquals("FormKiQ Server - Equifax", getTitle()); waitUntil(new Predicate<WebDriver>() { @Override public boolean apply(final WebDriver d) { WebElement e = findElements(By.xpath("//table[@id='results']")).get(0); return e.getText().contains("THOMAS"); } }); int i = 0; final int size = 6; List<WebElement> e = findElements(By.xpath("//table[@id='results']/tbody/tr/td")); assertEquals(size, e.size()); assertNotNull(e.get(i++).getText()); assertEquals("NEW", e.get(i++).getText()); assertEquals("https://uat.equifax.ca/sts/processinquiry.asp", e.get(i++).getText()); assertEquals("test", e.get(i++).getText()); assertNotNull(e.get(i++).getText()); assertNotNull(e.get(i++).getText()); }
From source file:com.formkiq.web.FolderIntegrationTest.java
License:Apache License
/** * testAddFolder02().// ww w.ja v a 2 s.com * add folder * * @throws Exception Exception */ @Test public void testAddFolder02() throws Exception { // given String folder = "testfolder"; // when findElementBy(By.id("folder_add_button")).click(); getWait().until(ExpectedConditions.visibilityOfElementLocated(By.id("form-modal"))); findElementBy("input", "data-valuekey", "name").sendKeys(folder); WebElement el = findElementBy(By.name("_eventId_next")); assertEquals("Add Folder", el.getText()); el.click(); // then getWait().until(ExpectedConditions.invisibilityOfElementLocated(By.id("form-modal"))); int i = 0; final int elementCount = 2; List<WebElement> e = findElements(By.xpath("//table[@id='results']/tbody/tr/td")); assertEquals(elementCount, e.size()); assertEquals("testfolder", e.get(i++).getText()); assertEquals("", e.get(i++).getText()); // when findElementBy(By.id("tablesearch")).sendKeys("testf1"); findElementBy(By.id("buttonsearch")).click(); // then e = findElements(By.xpath("//table[@id='results']/tbody/tr")); assertEquals(1, e.size()); assertEquals("No Folder(s) found", e.get(0).getText()); // when findElementBy(By.id("tablesearch")).clear(); findElementBy(By.id("tablesearch")).sendKeys("testf"); findElementBy(By.id("buttonsearch")).click(); // then e = findElements(By.xpath("//table[@id='results']/tbody/tr")); assertEquals(1, e.size()); assertEquals("testfolder", e.get(0).getText()); }
From source file:com.formkiq.web.OAuthClientIntegrationTest.java
License:Apache License
/** * testOauth01().//w w w .jav a 2s . c o m * save blank oauth federation * * @throws Exception Exception */ @Test public void testOauthClient01() throws Exception { // given // when login(getDefaultEmail()); getDriver().navigate().to(getDefaultHostAndPort() + "/admin/clients"); // then assertEquals("FormKiQ Server - OAuth Clients", getTitle()); waitUntil(new Predicate<WebDriver>() { @Override public boolean apply(final WebDriver d) { WebElement e = findElements(By.xpath("//table[@id='results']")).get(0); return e.getText().contains("authorization_code"); } }); int i = 0; final int elementCount = 3; List<WebElement> e = findElements(By.xpath("//table[@id='results']/tbody/tr/td")); assertEquals(elementCount, e.size()); assertEquals("formkiq", e.get(i++).getText()); assertEquals("formkiq", e.get(i++).getText()); assertEquals("authorization_code,password,refresh_token", e.get(i++).getText()); }
From source file:com.formkiq.web.OAuthFederationIntegrationTest.java
License:Apache License
/** * assert No OAuth Federations is setup. */// ww w . ja v a2 s . c o m private void assertNoOAuthSetup() { waitUntil(new Predicate<WebDriver>() { @Override public boolean apply(final WebDriver d) { WebElement e = findElements(By.xpath("//table[@id='results']")).get(0); return e.getText().contains("No OAuth Federation(s) setup"); } }); }
From source file:com.formkiq.web.SeleniumTestBase.java
License:Apache License
/** * Find Elements with text./*from w w w . j a v a 2s .c o m*/ * @param by {@link By} * @return {@link List} */ protected List<WebElement> findElementsWithText(final By by) { List<WebElement> list = new ArrayList<>(); List<WebElement> elements = findElements(by); for (WebElement element : elements) { if (!isEmpty(element.getText())) { list.add(element); } } return list; }