Codota Logo
WebElement.getText
Code IndexAdd Codota to your IDE (free)

How to use
getText
method
in
org.openqa.selenium.WebElement

Best Java code snippets using org.openqa.selenium.WebElement.getText (Showing top 20 results out of 1,701)

Refine searchRefine arrow

  • PrintStream.println
  • WebElement.click
  • WebDriver.findElement
  • Common ways to obtain WebElement
private void myMethod () {
WebElement w =
  • Codota IconWebDriver driver;By by;driver.findElement(by)
  • Codota IconWebDriver driver;String id;driver.findElement(By.id(id))
  • Codota IconWebDriver driver;driver.findElement(By.tagName("body"))
  • Smart code suggestions by Codota
}
origin: stackoverflow.com

 List<WebElement> allElements = driver.findElements(By.xpath("//div[@id='...']/ul/li")); 

for (WebElement element: allElements) {
   System.out.println(element.getText());
}
origin: stackoverflow.com

 WebElement select = driver.findElement(By.name("myselect"));
Select dropDown = new Select(select);           
String selected = dropDown.getFirstSelectedOption().getText();
if(selected.equals(valueToSelect)){
  //already selected; 
  //do stuff
}
List<WebElement> Options = dropDown.getOptions();
for(WebElement option:Options){
  if(option.getText().equals(valueToSelect)) {
   option.click(); //select option here;       
  }               
}
origin: cloudfoundry/uaa

  private void saveAlertErrorMessage() {
    try {
      WebElement element = webDriver.findElement(By.className("alert-error"));
      alertError = Optional.of(element.getText());
    } catch (NoSuchElementException _) {
      // do nothing
    }
  }
}
origin: cloudfoundry/uaa

webDriver.get(authUrl);
webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]"));
webDriver.findElement(By.name("username")).clear();
webDriver.findElement(By.name("username")).sendKeys("marissa5");
webDriver.findElement(By.name("password")).sendKeys("saml5");
webDriver.findElement(By.xpath("//input[@value='Login']")).click();
assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to?"));
System.out.println("cookie = " + String.format("%s=%s",cookie.getName(), cookie.getValue()));
origin: cloudfoundry/uaa

  private void signIn(String userName, String password) {
    webDriver.get(baseUrl + "/logout.do");
    webDriver.get(baseUrl + "/login");
    webDriver.findElement(By.name("username")).sendKeys(userName);
    webDriver.findElement(By.name("password")).sendKeys(password);
    webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();
    assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), containsString("Where to?"));
  }
}
origin: cloudfoundry/uaa

webDriver.findElement(By.name("username")).sendKeys(user.getUserName());
webDriver.findElement(By.name("password")).sendKeys(user.getPassword());
webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();
Assert.assertEquals("Application Authorization", webDriver.findElement(By.cssSelector("h1")).getText());
webDriver.findElement(By.xpath("//label[text()='Change your password']/preceding-sibling::input")).click();
webDriver.findElement(By.xpath("//label[text()='Read user IDs and retrieve users by ID']/preceding-sibling::input")).click();
webDriver.findElement(By.xpath("//label[text()='Read about your clouds.']/preceding-sibling::input"));
webDriver.findElement(By.xpath("//button[text()='Authorize']")).click();
Assert.assertEquals("Sample Home Page", webDriver.findElement(By.cssSelector("h1")).getText());
webDriver.findElement(By.linkText("Revoke Access")).click();
Assert.assertEquals("Are you sure you want to revoke access to The Ultimate Oauth App?", webDriver.findElement(By.cssSelector(".revocation-modal p")).getText());
origin: testcontainers/testcontainers-java

protected void doSimpleWebdriverTest(BrowserWebDriverContainer rule) {
  RemoteWebDriver driver = setupDriverFromRule(rule);
  System.out.println("Selenium remote URL is: " + rule.getSeleniumAddress());
  System.out.println("VNC URL is: " + rule.getVncAddress());
  driver.get("http://www.google.com");
  WebElement search = driver.findElement(By.name("q"));
  search.sendKeys("testcontainers");
  search.submit();
  List<WebElement> results = new WebDriverWait(driver, 15)
    .until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("#search h3")));
  assertTrue("the word 'testcontainers' appears in search results",
    results.stream()
      .anyMatch(el -> el.getText().contains("testcontainers")));
}
origin: cloudfoundry/uaa

webDriver.get(authUrl);
webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]"));
webDriver.findElement(By.name("username")).clear();
webDriver.findElement(By.name("username")).sendKeys("marissa6");
webDriver.findElement(By.name("password")).sendKeys("saml6");
webDriver.findElement(By.xpath("//input[@value='Login']")).click();
assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to?"));
System.out.println("cookie = " + String.format("%s=%s",cookie.getName(), cookie.getValue()));
origin: cloudfoundry/uaa

private String startCreateUserFlow(String secret) {
  String userEmail = "user" + new SecureRandom().nextInt() + "@example.com";
  webDriver.get(baseUrl + "/");
  webDriver.findElement(By.xpath("//*[text()='Create account']")).click();
  assertEquals("Create your account", webDriver.findElement(By.tagName("h1")).getText());
  webDriver.findElement(By.name("email")).sendKeys(userEmail);
  webDriver.findElement(By.name("password")).sendKeys(secret);
  webDriver.findElement(By.name("password_confirmation")).sendKeys(secret);
  webDriver.findElement(By.xpath("//input[@value='Send activation link']")).click();
  return userEmail;
}
origin: cloudfoundry/uaa

private void assertMessage(String expected) {
  assertEquals(expected, webDriver.findElement(By.id("message")).getText());
}
origin: cloudfoundry/uaa

  assertNotNull(element);
  element.click();
try {
  webDriver.findElement(By.xpath("//h1[contains(text(), 'Welcome to The Twiglet Zone[" + idpZoneId + "]!')]"));
  webDriver.findElement(By.name("username")).clear();
  webDriver.findElement(By.name("username")).sendKeys(idpZoneUserEmail);
  webDriver.findElement(By.name("password")).sendKeys("secr3T");
  webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();
  assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), containsString("Where to?"));
  Cookie afterLogin = webDriver.manage().getCookieNamed("JSESSIONID");
  assertNotNull(afterLogin);
origin: la-team/light-admin

private void selectFromFilteredList( String labelToSelect ) {
  for ( WebElement option : valueList.findElements( By.tagName( "li" ) ) ) {
    if ( option.getText().equals( labelToSelect ) )
      option.click();
  }
}
origin: stackoverflow.com

 try{
    WebElement byId = driver.findElement(By.id("by-id"));

    System.out.println(byId.getTagName());

    System.out.println("get the text for web element with id='by-id' ");
    System.out.println("------------------------------------------------------------");
    System.out.println(byId.getText());
    System.out.println("------------------------------------------------------------");
    System.out.println(byId.getAttribute("id"));
    System.out.println(byId.getCssValue("font-size"));
  }
}
origin: cloudfoundry/uaa

@Test
public void testDisplayIdentityZoneNameOnVerifyPage() {
  performLogin(username);
  webDriver.findElement(By.id("Next")).click();
  assertEquals(zoneUrl + "/login/mfa/verify", webDriver.getCurrentUrl());
  assertEquals(webDriver.findElement(By.id("mfa-identity-zone")).getText(), mfaZone.getName());
  webDriver.findElement(By.id("verify_code_btn")).click();
  assertEquals(webDriver.findElement(By.id("mfa-identity-zone")).getText(), mfaZone.getName());
}
origin: cloudfoundry/uaa

  @Test
  public void testMethodNotAllowedRoutedToErrorPage() throws Exception {
    webDriver.get(baseUrl + "/authenticate");

    Assert.assertTrue("Check if on the error page", webDriver.findElement(By.tagName("h2")).getText().contains("Uh oh."));
    Assert.assertTrue("Check if on the error page", webDriver.findElement(By.tagName("h2")).getText().contains("Something went amiss."));
  }
}
origin: cloudfoundry/uaa

element.click();
webDriver.findElement(By.xpath("//h1[contains(text(), 'Welcome to The Twiglet Zone[" + zoneId + "]!')]"));
webDriver.findElement(By.name("username")).clear();
webDriver.findElement(By.name("username")).sendKeys(zoneUserEmail);
webDriver.findElement(By.name("password")).sendKeys("secr3T");
webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();
assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), containsString("Where to?"));
origin: stackoverflow.com

 WebElement emailElement = driver.findElement(By.id("email"));
emailElement.sendKeys("ABCDEFG@g.com");

WebElement usernameElement = driver.findElement(By.id("username"));
usernameElement.click(); // Here, autocomplete is done

String userName = usernameElement.getText(); // get the value
assertEquals("ABCDEFG@g.com", userName);
origin: cloudfoundry/uaa

private void beginPasswordReset(String username) {
  webDriver.get(baseUrl + "/login");
  Assert.assertEquals("Cloud Foundry", webDriver.getTitle());
  webDriver.findElement(By.linkText("Reset password")).click();
  Assert.assertEquals("Reset Password", webDriver.findElement(By.tagName("h1")).getText());
  // Enter email address
  webDriver.findElement(By.name("username")).sendKeys(username);
  webDriver.findElement(By.xpath("//input[@value='Send reset password link']")).click();
  Assert.assertEquals("Instructions Sent", webDriver.findElement(By.tagName("h1")).getText());
}
origin: cloudfoundry/uaa

@Test
public void testChangeEmailWithoutLogout() throws Exception {
  String newEmail = testChangeEmail(false);
  assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), containsString("Account Settings"));
  assertThat(webDriver.findElement(By.cssSelector(".alert-success")).getText(), containsString("Email address successfully verified."));
  assertThat(webDriver.findElement(By.cssSelector(".nav")).getText(), containsString(newEmail));
  assertThat(webDriver.findElement(By.cssSelector(".profile")).getText(), containsString(newEmail));
}
origin: cloudfoundry/uaa

assertEquals(2, elements.size());
WebElement element = webDriver.findElement(By.xpath("//a[text()='" + samlIdentityProviderDefinition1.getLinkText() + "']"));
assertNotNull(element);
element = webDriver.findElement(By.xpath("//a[text()='" + samlIdentityProviderDefinition.getLinkText() + "']"));
element.click();
webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]"));
webDriver.findElement(By.name("username")).clear();
webDriver.findElement(By.name("username")).sendKeys(testAccounts.getUserName());
webDriver.findElement(By.name("password")).sendKeys(testAccounts.getPassword());
webDriver.findElement(By.xpath("//input[@value='Login']")).click();
assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to?"));
org.openqa.seleniumWebElementgetText

Javadoc

Get the visible (i.e. not hidden by CSS) innerText of this element, including sub-elements, without any leading or trailing whitespace.

Popular methods of WebElement

  • click
    Click this element. If this causes a new page to load, you should discard all references to this ele
  • sendKeys
    Use this method to simulate typing into an element, which may set its value.
  • getAttribute
    Get the value of the given attribute of the element. Will return the current value, even if this has
  • clear
    If this element is a text entry element, this will clear the value. Has no effect on other elements.
  • isDisplayed
    Is this element displayed or not? This method avoids the problem of having to parse an element's "st
  • findElements
    Find all elements within the current context using the given mechanism. When using xpath be aware th
  • isSelected
    Determine whether or not this element is selected or not. This operation only applies to input eleme
  • findElement
    Find the first WebElement using the given method. See the note in #findElements(By) about finding vi
  • getTagName
    Get the tag name of this element. Not the value of the name attribute: will return"input" for the el
  • isEnabled
    Is the element currently enabled or not? This will generally return true for everything but disabled
  • getLocation
    Where on the page is the top left-hand corner of the rendered element?
  • submit
    If this current element is a form, or an element within a form, then this will be submitted to the r
  • getLocation,
  • submit,
  • getSize,
  • getCssValue,
  • getRect,
  • getScreenshotAs,
  • getValue,
  • setSelected,
  • toggle

Popular in Java

  • Start an intent from android
  • startActivity (Activity)
  • requestLocationUpdates (LocationManager)
  • onRequestPermissionsResult (Fragment)
  • BigInteger (java.math)
    Immutable arbitrary-precision integers. All operations behave as if BigIntegers were represented in
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
  • Logger (org.slf4j)
    The main user interface to logging. It is expected that logging takes place through concrete impleme
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.This exception may include information for locating the er
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now