Java Code Examples for org.openqa.selenium.WebElement#getText()
The following examples show how to use
org.openqa.selenium.WebElement#getText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BasicMouseInterfaceTest.java From selenium with Apache License 2.0 | 5 votes |
private ExpectedCondition<Boolean> fuzzyMatchingOfCoordinates( final WebElement element, final int x, final int y) { return new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver ignored) { return fuzzyPositionMatching(x, y, element.getText()); } @Override public String toString() { return "Coordinates: " + element.getText() + " but expected: " + x + ", " + y; } }; }
Example 2
Source File: WebDriverAftBase.java From rice with Educational Community License v2.0 | 5 votes |
protected void assertJgrowlText(String jGrowlText) throws InterruptedException { waitForElementPresentByClassName("jGrowl-message"); // wait for any flash not present errors to fade out while (jGrowlTextContains("Unable to load SWF file")) { try { driver.findElement(By.className("jGrowl-close")).click(); // no wait, click quick } catch (Throwable t) { // don't fail because the swf jgrowl has gone away } } // get growl texts StringBuilder sb = new StringBuilder(""); List<WebElement> jGrowls = findElements(By.className("jGrowl-message")); for (WebElement jGrowl : jGrowls) { if (jGrowl.getText() != null) { sb.append(jGrowl.getText()).append("\n"); } } String growlText = sb.toString(); WebDriverUtils.stepMessage("Do jGrowls contain text '" + jGrowlText + "'? " + growlText.contains(jGrowlText)); //check growl text is present assertTrue(growlText + " does not contain " + jGrowlText, growlText.contains(jGrowlText)); }
Example 3
Source File: LibraryFieldsKimLinkBase.java From rice with Educational Community License v2.0 | 5 votes |
protected void verifyLinkDataItem(WebElement field, String inputFieldName, String inputFieldValue)throws Exception { jGrowl("verifyLinkDataItem"); waitAndClickById(field.getAttribute(ID_ATTRIBUTE)); gotoLightBox(); WebElement inquiryPage = findElement(By.xpath(("//main[contains(@class,'uif-inquiryPage')]"))); WebElement inputField = findElement(By.xpath("//td/div[@data-label='"+inputFieldName+"']/span"),inquiryPage); String fieldText = inputField.getText(); if ( !StringUtils.contains(fieldText,inputFieldValue)) { fail("Expected value not found on field. Expected " + inputFieldValue + " but found " + fieldText); } waitAndClickButtonByText("Close", "Unable to find Close button"); selectTopFrame(); }
Example 4
Source File: WebDriverLegacyITBase.java From rice with Educational Community License v2.0 | 5 votes |
/** * Uses Selenium's findElements method which does not throw a test exception if not found. * @param errorTextToMatch * @return */ public boolean hasDocError(String errorTextToMatch) { if (driver.findElements(By.xpath(DIV_ERROR_LOCATOR)).size() > 0) { String errorText = driver.findElement(By.xpath(DIV_ERROR_LOCATOR)).getText(); // don't highlight if (errorText != null && errorText.contains("error(s) found on page.")) { WebElement errorDiv = driver.findElement(By.xpath("//div[@class='left-errmsg']/div[2]/div")); // don't highlight if (errorDiv != null) { errorText = errorDiv.getText(); return errorText != null && errorText.contains(errorTextToMatch); } } } return false; }
Example 5
Source File: JTableTest.java From marathonv5 with Apache License 2.0 | 5 votes |
public void gettableCellNonexistant() throws Throwable { driver = new JavaDriver(); WebElement errCell = driver.findElement(By.cssSelector("table::mnth-cell(20,20)")); try { errCell.getText(); throw new MissingException(NoSuchElementException.class); } catch (NoSuchElementException e) { } }
Example 6
Source File: SystemPerformanceDemo.java From query2report with GNU General Public License v3.0 | 5 votes |
@Test public void step2CreateConnection() throws InterruptedException { driver.navigate().refresh(); driver.findElement(By.id("connmgmt")).click(); Thread.sleep(2000); driver.findElement(By.id("addConnectionButton")).click(); Thread.sleep(1000); driver.findElement(By.id("aliasInput")).sendKeys("MySQL"); Thread.sleep(1000); driver.findElement(By.id("driverSelect")).sendKeys("MySQL"); Thread.sleep(1000); driver.findElement(By.id("urlInput")).sendKeys("jdbc:mysql://localhost:3306/sys"); Thread.sleep(1000); driver.findElement(By.id("usernameInput")).sendKeys("root"); Thread.sleep(1000); driver.findElement(By.id("passwordInput")).sendKeys("root"); Thread.sleep(5000); driver.findElement(By.id("saveConnectionButton")).click(); Thread.sleep(1000); driver.findElement(By.xpath("//button[contains(.,'Ok')]")).click(); WebElement elem = driver.findElement(By.tagName("h2")); String textToAssert = elem.getText(); Assert.assertEquals(true, textToAssert.contains("Save of alias 'MySQL' Succeeded")); Thread.sleep(1000); driver.findElement(By.id("MySQLTestConnectionButton")).click(); Thread.sleep(5000); driver.findElement(By.xpath("//button[contains(.,'Ok')]")).click(); elem = driver.findElement(By.tagName("h2")); textToAssert = elem.getText(); Assert.assertEquals(true, textToAssert.contains("Connection to alias 'MySQL' Succeeded")); }
Example 7
Source File: TestApplicationListUtil.java From windup with Eclipse Public License 1.0 | 5 votes |
/** * Returns the list of application names on the application list. */ public List<String> getApplicationNames() { List<String> result = new ArrayList<>(); List<WebElement> appInfoElements = getDriver().findElements(By.cssSelector(".appInfo")); for (WebElement appInfoRow : appInfoElements) { WebElement filename = appInfoRow.findElement(By.cssSelector(".fileName")); if (filename != null && filename.getText() != null) result.add(filename.getText().trim()); } return Collections.unmodifiableList(result); }
Example 8
Source File: Ex01PO.java From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 | 5 votes |
public Integer getCounterValue(){ WebElement text = getDriver().findElement(By.id("form:counterTextId")); String value = text.getText(); try{ return Integer.parseInt(value); } catch (Exception e) { return null; } }
Example 9
Source File: NativeEventsTest.java From marathonv5 with Apache License 2.0 | 5 votes |
public void exitedGeneratesSameEvents() throws Throwable { events = MouseEvent.MOUSE_EXITED; SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { actionsArea.setText(""); } }); driver = new JavaDriver(); WebElement b = driver.findElement(By.name("click-me")); WebElement t = driver.findElement(By.name("actions")); Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen"); Dimension size = EventQueueWait.call_noexc(button, "getSize"); Robot r = new Robot(); r.setAutoDelay(10); r.setAutoWaitForIdle(true); r.keyPress(KeyEvent.VK_ALT); r.mouseMove(location.x + size.width / 2, location.y + size.height / 2); r.mousePress(InputEvent.BUTTON1_MASK); r.mouseRelease(InputEvent.BUTTON1_MASK); Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen"); Dimension size2 = EventQueueWait.call_noexc(button, "getSize"); r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2); r.mousePress(InputEvent.BUTTON1_MASK); r.mouseRelease(InputEvent.BUTTON1_MASK); r.keyRelease(KeyEvent.VK_ALT); new EventQueueWait() { @Override public boolean till() { return actionsArea.getText().length() > 0; } }.wait("Waiting for actionsArea failed?"); String expected = t.getText(); tclear(); new Actions(driver).moveToElement(t).keyDown(Keys.ALT).moveToElement(b).moveToElement(t).keyUp(Keys.ALT).perform(); AssertJUnit.assertEquals(expected, t.getText()); }
Example 10
Source File: JQueryTestBase.java From htmlunit with Apache License 2.0 | 5 votes |
/** * @param webdriver the web driver * @param testNumber the number of the test to run * @return the test result details */ protected String getResultDetailElementText(final WebDriver webdriver, final String testNumber) { final WebElement output = webdriver.findElement(By.id("qunit-test-output0")); String result = output.getText(); result = result.substring(0, result.indexOf("Rerun")).trim(); return result; }
Example 11
Source File: NavigationPage.java From aws-device-farm-appium-cucumber-tests-for-sample-app with Apache License 2.0 | 5 votes |
/** * Go to a specific category within the navigation drawer * * @param categoryName category */ public void gotoCategory(String categoryName) { int counter = 0; toggle.click(); try { Thread.sleep(WaitConfig.DRAWER_ANIMATION_WAIT); } catch (InterruptedException e) { e.printStackTrace(); } WebElement categoryElement = null; List<WebElement> categoryElements; while (categoryElement == null) { counter++; if (counter == TRIES) return; categoryElements = driver.findElementsById("com.amazonaws.devicefarm.android.referenceapp:id/drawer_row_title"); for (WebElement categoryTitleElement: categoryElements){ String titleText = categoryTitleElement.getText(); if (titleText.equalsIgnoreCase(categoryName)) categoryElement = categoryTitleElement; } if (categoryElement == null) { driver.scrollTo(categoryName); } } categoryElement.click(); }
Example 12
Source File: ThirdPartyBrowserTest.java From caja with Apache License 2.0 | 5 votes |
/** * For QUnit-based tests, read QUnit's status text to determine if progress is * being made. */ @Override protected void waitForCompletion(final WebDriver driver) { final String testResultId = "qunit-testresult-caja-guest-0___"; if (driver.findElements(By.id(testResultId)).size() == 0) { // Not a QUnit test case; use default behavior. super.waitForCompletion(driver); return; } // Let it run as long as the report div's text is changing WebElement statusElement = driver.findElement(By.id(testResultId)); String currentStatus = statusElement.getText(); String lastStatus = null; // Check every second. // If the text starts with "Tests completed", then we're done. // If the text has changed, reset the time limit. int limit = 30; // tries for (int chances = limit; chances > 0; --chances) { if (currentStatus.startsWith("Tests completed")) { break; } try { Thread.sleep(1000); } catch (InterruptedException e) { // Keep trying } statusElement = driver.findElement(By.id(testResultId)); lastStatus = currentStatus; currentStatus = statusElement.getText(); if (!lastStatus.equals(currentStatus)) { chances = limit; } } }
Example 13
Source File: NoraUiExpectedConditions.java From NoraUi with GNU Affero General Public License v3.0 | 5 votes |
/** * text to be presentInElement on element located. * * @param locator * is the selenium locator * @return content string (not empty). */ public static ExpectedCondition<String> textToBePresentInElement(final By locator) { return (@Nullable WebDriver driver) -> { try { final WebElement element = driver.findElement(locator); if (element != null && element.getText() != null && !"".equals(element.getText())) { return element.getText(); } } catch (final Exception e) { } return null; }; }
Example 14
Source File: EncapsulateOperation.java From LuckyFrameClient with GNU Affero General Public License v3.0 | 5 votes |
public static String getOperation(WebDriver wd, WebElement we, String operation, String value) { String result = ""; // ��ȡ������ switch (operation) { case "gettext": result = "��ȡ����ֵ�ǡ�" + we.getText() + "��"; LogUtil.APP.info("getText��ȡ����text����...��text����ֵ:{}��",result); break; // ��ȡ��������� case "gettagname": result = "��ȡ����ֵ�ǡ�" + we.getTagName() + "��"; LogUtil.APP.info("getTagName��ȡ����tagname����...��tagname����ֵ:{}��",result); break; case "getattribute": result = "��ȡ����ֵ�ǡ�" + we.getAttribute(value) + "��"; LogUtil.APP.info("getAttribute��ȡ����{}������...��{}����ֵ:{}��",value,value,result); break; case "getcssvalue": result = "��ȡ����ֵ�ǡ�" + we.getCssValue(value) + "��"; LogUtil.APP.info("getCssValue��ȡ����{}������...��{}����ֵ:{}��",value,value,result); break; case "getcaptcha": result = "��ȡ����ֵ�ǡ�" + Ocr.getCAPTCHA(wd, we) + "��"; LogUtil.APP.info("getcaptcha��ȡ��֤��...����֤��ֵ:{}��",result); break; default: break; } return result; }
Example 15
Source File: AccountApplicationsPage.java From keycloak with Apache License 2.0 | 4 votes |
public Map<String, AppEntry> getApplications() { Map<String, AppEntry> table = new HashMap<String, AppEntry>(); for (WebElement r : driver.findElements(By.tagName("tr"))) { int count = 0; AppEntry currentEntry = null; for (WebElement col : r.findElements(By.tagName("td"))) { count++; switch (count) { case 1: currentEntry = new AppEntry(); String client = col.getText(); WebElement link = null; try { link = col.findElement(By.tagName("a")); String href = link.getAttribute("href"); currentEntry.setHref(href); } catch (Exception e) { //ignore } table.put(client, currentEntry); break; case 2: String rolesStr = col.getText(); String[] roles = rolesStr.split(","); for (String role : roles) { role = role.trim(); currentEntry.addAvailableRole(role); } break; case 3: String clientScopesStr = col.getText(); if (clientScopesStr.isEmpty()) break; String[] clientScopes = clientScopesStr.split(","); for (String clientScope : clientScopes) { clientScope = clientScope.trim(); currentEntry.addGrantedClientScope(clientScope); } break; case 4: String additionalGrant = col.getText(); if (additionalGrant.isEmpty()) break; String[] grants = additionalGrant.split(","); for (String grant : grants) { grant = grant.trim(); currentEntry.addAdditionalGrant(grant); } break; } } } table.remove("Application"); return table; }
Example 16
Source File: NewQuestionPage.java From mamute with Apache License 2.0 | 4 votes |
private boolean hasDescription(String questionDescription) { WebElement textArea = formField("description"); String actual = textArea.getText(); return questionDescription.equals(actual); }
Example 17
Source File: InventoryPage.java From demo-java with MIT License | 4 votes |
public String getItemDescription(int itemNumber) { WebElement itemDesc = getItemNumber(itemNumber).findElement(By.className("inventory_item_desc")); return itemDesc.getText(); }
Example 18
Source File: NativeEventsTest.java From marathonv5 with Apache License 2.0 | 4 votes |
private void checkKeyEvent(int eventToCheck, String keysToSend, int... keysToPress) throws InterruptedException, InvocationTargetException, AWTException { events = eventToCheck; SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { actionsArea.setText(""); } }); driver = new JavaDriver(); WebElement b = driver.findElement(By.name("enter-text")); WebElement t = driver.findElement(By.name("actions")); Point location = EventQueueWait.call_noexc(textField, "getLocationOnScreen"); Dimension size = EventQueueWait.call_noexc(textField, "getSize"); Robot r = new Robot(); r.setAutoDelay(10); r.setAutoWaitForIdle(true); r.mouseMove(location.x + size.width / 2, location.y + size.height / 2); r.mousePress(InputEvent.BUTTON1_MASK); r.mouseRelease(InputEvent.BUTTON1_MASK); for (int keysToPres : keysToPress) { r.keyPress(keysToPres); } for (int i = keysToPress.length - 1; i >= 0; i--) { r.keyRelease(keysToPress[i]); } new EventQueueWait() { @Override public boolean till() { return actionsArea.getText().length() > 0; } }.wait("Waiting for actionsArea failed?"); String expected = t.getText(); tclear(); Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen"); Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize"); r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2); r.mousePress(InputEvent.BUTTON1_MASK); r.mouseRelease(InputEvent.BUTTON1_MASK); b.sendKeys(keysToSend); System.out.println("Expected: " + expected); AssertJUnit.assertEquals(expected, t.getText()); new Actions(driver).moveToElement(b).click().perform(); AssertJUnit.assertEquals(expected, t.getText()); }
Example 19
Source File: TagInvestigationTest.java From webDriverExperiments with MIT License | 4 votes |
@Test public void myStuff(){ Set<String> tags = new HashSet<String>(); List<WebElement> elements = driver.findElements(By.cssSelector("*")); // get everything System.out.println(" TAG [ Text | Attribute ]"); for(WebElement element : elements){ String getText = element.getText(); String getAttribute = element.getAttribute("text"); int getTextLen = 0; int maxStringLen = 0; int getAttributeLen=0; if(getText != null){ getTextLen = getText.length(); if(getTextLen>0) maxStringLen = (getTextLen>16) ? 15 : getTextLen -1; getText = getText.replaceAll("\n","").substring(0, maxStringLen); getText = (getTextLen > 16) ? getText + "..." : getText; } maxStringLen = 0; if(getAttribute != null){ getAttributeLen = getAttribute.length(); if(getAttributeLen>0) maxStringLen = (getAttributeLen>16) ? 15 : getAttributeLen -1; getAttribute = getAttribute.replaceAll("\n","").substring(0, maxStringLen); getAttribute = (getAttributeLen > 16) ? getAttribute + "..." : getAttribute; } if(!tags.contains(element.getTagName())){ System.out.println(element.getTagName()); System.out.println(" - getText : " + "(" + getTextLen + ")" + getText); System.out.println(" - getAttribute : " + "(" + getAttributeLen + ")" + getAttribute); } tags.add(element.getTagName()); if(getAttributeLen > getTextLen){ System.out.println("***" + element.getTagName() + "[" + getTextLen + "]" + " vs " + getAttribute); } } }
Example 20
Source File: NativeEventsTest.java From marathonv5 with Apache License 2.0 | 4 votes |
public void pressGeneratesSameEvents() throws Throwable { events = MouseEvent.MOUSE_PRESSED; SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { actionsArea.setText(""); } }); driver = new JavaDriver(); WebElement b = driver.findElement(By.name("click-me")); WebElement t = driver.findElement(By.name("actions")); Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen"); Dimension size = EventQueueWait.call_noexc(button, "getSize"); Robot r = new Robot(); r.setAutoDelay(10); r.setAutoWaitForIdle(true); r.mouseMove(location.x + size.width / 2, location.y + size.height / 2); r.mousePress(InputEvent.BUTTON1_MASK); r.mouseRelease(InputEvent.BUTTON1_MASK); new EventQueueWait() { @Override public boolean till() { return actionsArea.getText().length() > 0; } }.wait("Waiting for actionsArea failed?"); String expected = t.getText(); tclear(); Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen"); Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize"); r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2); r.mousePress(InputEvent.BUTTON1_MASK); r.mouseRelease(InputEvent.BUTTON1_MASK); b.click(); AssertJUnit.assertEquals(expected, t.getText()); tclear(); new Actions(driver).moveToElement(b).click().perform(); AssertJUnit.assertEquals(expected, t.getText()); }