Tabnine Logo
WebElement
Code IndexAdd Tabnine to your IDE (free)

How to use
WebElement
in
org.openqa.selenium

Best Java code snippets using org.openqa.selenium.WebElement (Showing top 20 results out of 2,349)

Refine searchRefine arrow

  • By
  • WebDriver
  • FirefoxDriver
  • URL
  • RunAsClient
  • ExpectedConditions
  • WebDriverWait
  • Select
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: galenframework/galen

@Override
public String getText() {
  WebElement webElement = getWebElement();
  if ("input".equals(webElement.getTagName().toLowerCase())) {
    String value = webElement.getAttribute("value");
    if (value == null) {
      value = "";
    }
    
    return value;
  }
  else return getWebElement().getText().trim();
}
origin: spring-io/initializr

public void artifactId(String text) {
  this.form.findElement(By.id("artifactId")).clear();
  this.form.findElement(By.id("artifactId")).sendKeys(text);
}
origin: selenide/selenide

 private void setSelected(WebElement option) {
  if (!option.isSelected()) {
   option.click();
  }
 }
}
origin: selenide/selenide

private String serialize() {
 String text = element.getText();
 sb.append('>').append(text == null ? "" : text).append("</").append(element.getTagName()).append('>');
 return sb.toString();
}
origin: org.juzu/juzu-core

 @Test
 @RunAsClient
 public void test() throws Exception {
  driver.get(applicationURL().toString());
  System.out.println(driver.getPageSource());
  WebDriverWait wait = new WebDriverWait(driver, 5);
  wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html[@bar]")));
  WebElement elt = driver.findElement(By.tagName("html"));
  assertEquals("<bar>foo_value</bar>", elt.getAttribute("bar"));
 }
}
origin: cloudfoundry/uaa

  @Test
  public void testEmailDomainRegisteredWithIDPDoesNotAllowAccountCreation() throws Exception {
    String adminToken = IntegrationTestUtils.getClientCredentialsToken(baseUrl, "admin", "adminsecret");
    IdentityProvider<OIDCIdentityProviderDefinition> oidcProvider = new IdentityProvider().setName("oidc_provider").setActive(true).setType(OriginKeys.OIDC10).setOriginKey(OriginKeys.OIDC10).setConfig(new OIDCIdentityProviderDefinition());
    oidcProvider.getConfig().setAuthUrl(new URL("http://example.com"));
    oidcProvider.getConfig().setShowLinkText(false);
    oidcProvider.getConfig().setTokenUrl(new URL("http://localhost:8080/uaa/idp_login"));
    oidcProvider.getConfig().setTokenKeyUrl(new URL("http://localhost:8080/uaa/idp_login"));
    oidcProvider.getConfig().setEmailDomain(Collections.singletonList("example.com"));
    oidcProvider.getConfig().setRelyingPartyId("client_id");
    oidcProvider.getConfig().setRelyingPartySecret("client_secret");
    IntegrationTestUtils.createOrUpdateProvider(adminToken, baseUrl, oidcProvider);
    try {

      startCreateUserFlow("test");

      assertEquals("Account sign-up is not required for this email domain. Please login with the identity provider", webDriver.findElement(By.cssSelector(".alert-error")).getText());
      webDriver.findElement(By.xpath("//input[@value='Login with provider']")).click();
      assertThat(webDriver.getCurrentUrl(), startsWith(oidcProvider.getConfig().getAuthUrl().toString()));
    } finally {
      IntegrationTestUtils.deleteProvider(adminToken, baseUrl, OriginKeys.UAA, OriginKeys.OIDC10);
    }
  }
}
origin: cloudfoundry/uaa

@Test
public void login_with_wrong_keys() throws Exception {
  identityProvider.getConfig().setTokenKeyUrl(new URL("https://login.microsoftonline.com/9bc40aaf-e150-4c30-bb3c-a8b3b677266e/discovery/v2.0/keys"));
  updateProvider();
  webDriver.get(zoneUrl + "/login");
  webDriver.findElement(By.linkText("My OIDC Provider")).click();
  Assert.assertThat(webDriver.getCurrentUrl(), containsString(baseUrl));
  webDriver.findElement(By.name("username")).sendKeys("marissa");
  webDriver.findElement(By.name("password")).sendKeys("koala");
  webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();
  Assert.assertThat(webDriver.getCurrentUrl(), containsString(zoneUrl + "/oauth_error?error=There+was+an+error+when+authenticating+against+the+external+identity+provider"));
  List<String> cookies = IntegrationTestUtils.getAccountChooserCookies(zoneUrl, webDriver);
  assertThat(cookies, not(Matchers.hasItem(startsWith("Saved-Account-"))));
}
origin: cloudfoundry/uaa

URL inviteLink = response.getBody().getNewInvites().get(0).getInviteLink();
webDriver.get(inviteLink.toString());
webDriver.findElement(By.xpath("//h1[contains(text(), 'Welcome')]"));
webDriver.findElement(By.name("username")).clear();
webDriver.findElement(By.name("username")).sendKeys("marissa");
webDriver.findElement(By.name("password")).sendKeys("koala");
webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();
origin: com.github.jjYBdx4IL/github-test-utils

@Test
public void testSetInputFieldValue_String_String() throws Exception {
  getDriver().get(testPage1.toExternalForm());
  setInputFieldValue("inputName1", "valueOfInputName1");
  WebElement el = getDriver().findElement(By.xpath("//input[@name='inputName1']"));
  assertEquals("valueOfInputName1", el.getAttribute("value"));
  setInputFieldValue("selectName", "GenericVal");
  el = getDriver().findElement(By.xpath("//select[@name='selectName']"));
  assertEquals("GenericVal", new Select(el).getFirstSelectedOption().getAttribute("value"));
}
origin: TEAMMATES/teammates

public boolean isRadioButtonChecked(int rowIndex) {
  WebElement button = browser.driver.findElement(By.id("copyTableModal"))
                  .findElements(By.tagName("tr"))
                  .get(rowIndex + 1).findElement(By.tagName("input"));
  return button.isSelected();
}
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

@Test
public void testBannerFunctionalityInDiscoveryPage() {
  String zoneId = "testzone3";
  RestTemplate identityClient = IntegrationTestUtils.getClientCredentialsTemplate(
    IntegrationTestUtils.getClientCredentialsResource(baseUrl, new String[]{"zones.write", "zones.read", "scim.zones"}, "identity", "identitysecret")
  );
  IdentityZoneConfiguration config = new IdentityZoneConfiguration();
  config.setIdpDiscoveryEnabled(true);
  Banner banner = new Banner();
  banner.setText("test banner");
  banner.setBackgroundColor("#444");
  banner.setTextColor("#111");
  config.setBranding(new BrandingInformation());
  config.getBranding().setBanner(banner);
  IntegrationTestUtils.createZoneOrUpdateSubdomain(identityClient, baseUrl, zoneId, zoneId, config);
  String zoneUrl = baseUrl.replace("localhost",zoneId+".localhost");
  webDriver.get(zoneUrl);
  webDriver.manage().deleteAllCookies();
  webDriver.navigate().refresh();
  assertEquals("test banner", webDriver.findElement(By.cssSelector(".banner-header span")).getText());
  assertEquals("rgba(68, 68, 68, 1)", webDriver.findElement(By.cssSelector(".banner-header")).getCssValue("background-color"));
  assertEquals("rgba(17, 17, 17, 1)", webDriver.findElement(By.cssSelector(".banner-header span")).getCssValue("color"));
  String base64Val = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAATBJREFUeNqk008og3Ecx/HNnrJSu63kIC5qKRe7KeUiOSulTHJUTrsr0y5ycFaEgyQXElvt5KDYwU0uO2hSUy4KoR7v7/qsfmjPHvzq1e/XU8/39/3zPFHf9yP/WV7jED24nGRbxDFWUAsToM05zyKFLG60d/wmQBxWzwyOlMU1phELEyCmtPeRQRoVbKOM0VYB6q0QW+3IYQpJFFDEYFCAiMqwNY857Ko3SxjGBTbRXb+xMUamcMbWh148YwJvOHSCdyqTAdxZo72ADGwKT98C9CChcxUPQSVYLz50toae4Fy9WcAISl7AiN/RhS1N5RV5rOLxx5eom90pvGAI/VjHMm6bfspK18a1gXvsqM41XDVL052C1Tim56cYd/rR+mdSrXGluxfm5S8Z/HV9CjAAvQZLXoa5mpgAAAAASUVORK5CYII=";
  banner.setLogo(base64Val);
  IntegrationTestUtils.createZoneOrUpdateSubdomain(identityClient, baseUrl, zoneId, zoneId, config);
  webDriver.get(zoneUrl);
  assertEquals("data:image/png;base64," + base64Val, webDriver.findElement(By.cssSelector(".banner-header img")).getAttribute("src"));
  assertEquals(2, webDriver.findElement(By.cssSelector(".banner-header")).findElements(By.xpath(".//*")).size());
}
origin: cloudfoundry/uaa

@Test
public void testInvalidAppRedirectDisplaysError() throws Exception {
  ScimUser user = createUnapprovedUser(serverRunning);
  // given we vist the app (specifying an invalid redirect - incorrect protocol https)
  webDriver.get(appUrl + "?redirect_uri=https://localhost:8080/app/");
  // Sign in to login server
  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();
  // Authorize the app for some scopes
  assertThat(webDriver.findElement(By.className("alert-error")).getText(), IntegrationTestUtils.RegexMatcher.matchesRegex("^Invalid redirect (.*) did not match one of the registered values"));
}
origin: cloudfoundry/uaa

@Test
public void testQRCodeValidation() {
  performLogin(username);
  assertEquals(zoneUrl + "/login/mfa/register", webDriver.getCurrentUrl());
  webDriver.findElement(By.id("Next")).click();
  assertEquals(zoneUrl + "/login/mfa/verify", webDriver.getCurrentUrl());
  webDriver.findElement(By.name("code")).sendKeys("1111111111111111112222");
  webDriver.findElement(By.id("verify_code_btn")).click();
  assertEquals("Incorrect code, please try again.", webDriver.findElement(By.cssSelector("form .error-color")).getText());
}
origin: cloudfoundry/uaa

@Test
public void testLoginReloadRetainsFormRedirect() {
  String redirectUri = "http://expected.com";
  webDriver.get(baseUrl + "/oauth/authorize?client_id=test&redirect_uri="+redirectUri);
  ((JavascriptExecutor)webDriver).executeScript("document.getElementsByName('X-Uaa-Csrf')[0].value=''");
  webDriver.manage().deleteCookieNamed("JSESSIONID");
  webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();
  assertThat(webDriver.getCurrentUrl(), Matchers.containsString("/login"));
  assertThat(webDriver.findElement(By.name("form_redirect_uri")).getAttribute("value"), Matchers.containsString("redirect_uri="+redirectUri));
}
origin: appium/java-client

@Test public void hideKeyboardWithParametersTest() {
  new WebDriverWait(driver, 30)
      .until(ExpectedConditions.presenceOfElementLocated(By.id("IntegerA")))
      .click();
  driver.hideKeyboard(HideKeyboardStrategy.PRESS_KEY, "Done");
}
origin: cloudfoundry/uaa

@Test
public void testQRCodeScreen_ClickManualAndReturn() throws Exception{
  performLogin(username);
  assertEquals(zoneUrl + "/login/mfa/register", webDriver.getCurrentUrl());
  webDriver.findElement(By.linkText("manual setup instructions")).click();
  assertEquals(zoneUrl + "/login/mfa/manual", webDriver.getCurrentUrl());
  webDriver.findElement(By.id("Back")).click();
  assertEquals(zoneUrl + "/login/mfa/register", webDriver.getCurrentUrl());
  String imageSrc = webDriver.findElement(By.id("qr")).getAttribute("src");
  String secretKey = getSecretFromQrImageString(imageSrc);
  webDriver.findElement(By.id("Next")).click();
  verifyCodeOnRegistration(secretKey, "/");
}
origin: apache/geode

private void login() {
 WebElement userNameElement = waitForElementById("user_name", 60);
 WebElement passwordElement = waitForElementById("user_password");
 userNameElement.sendKeys(username);
 passwordElement.sendKeys(password);
 passwordElement.submit();
 driver.get(getPulseURL() + "clusterDetail.html");
 WebElement userNameOnPulsePage =
   (new WebDriverWait(driver, 30, 1000)).until(
     (ExpectedCondition<WebElement>) d -> d.findElement(By.id("userName")));
 assertNotNull(userNameOnPulsePage);
}
origin: cloudfoundry/uaa

@Test
public void displaysErrorWhenPasswordContravenesPolicy() {
  //the only policy we can contravene by default is the length
  String newPassword = new RandomValueStringGenerator(260).generate();
  webDriver.get(baseUrl + "/change_password");
  signIn(userEmail, PASSWORD);
  changePassword(PASSWORD, newPassword, newPassword);
  WebElement errorMessage = webDriver.findElement(By.className("error-message"));
  assertTrue(errorMessage.isDisplayed());
  assertEquals("Password must be no more than 255 characters in length.", errorMessage.getText());
}
org.openqa.seleniumWebElement

Javadoc

Represents an HTML element. Generally, all interesting operations to do with interacting with a page will be performed through this interface.

All method calls will do a freshness check to ensure that the element reference is still valid. This essentially determines whether or not the element is still attached to the DOM. If this test fails, then an org.openqa.selenium.StaleElementReferenceException is thrown, and all future calls to this instance will fail.

Most used methods

  • getText
    Get the visible (i.e. not hidden by CSS) text of this element, including sub-elements.
  • 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?
  • isEnabled,
  • getLocation,
  • submit,
  • getSize,
  • getCssValue,
  • getRect,
  • getScreenshotAs,
  • getValue,
  • setSelected,
  • toggle

Popular in Java

  • Updating database using SQL prepared statement
  • setContentView (Activity)
  • requestLocationUpdates (LocationManager)
  • getSystemService (Context)
  • FileNotFoundException (java.io)
    Thrown when a file specified by a program cannot be found.
  • String (java.lang)
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • Iterator (java.util)
    An iterator over a sequence of objects, such as a collection.If a collection has been changed since
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Option (scala)
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now