org.openqa.selenium.By.name()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(11.3k)|赞(0)|评价(0)|浏览(192)

本文整理了Java中org.openqa.selenium.By.name()方法的一些代码示例,展示了By.name()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。By.name()方法的具体详情如下:
包路径:org.openqa.selenium.By
类名称:By
方法名:name

By.name介绍

暂无

代码示例

代码示例来源:origin: selenide/selenide

/**
 * @see By#name(java.lang.String)
 * @since 3.1
 */
public static By byName(String name) {
 return By.name(name);
}

代码示例来源:origin: cloudfoundry/uaa

public void attemptLogin(String username, String password) {
  webDriver.findElement(By.name("username")).sendKeys(username);
  webDriver.findElement(By.name("password")).sendKeys(password);
  webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();
}

代码示例来源:origin: cloudfoundry/uaa

private void signIn(String userName, String password) {
    webDriver.findElement(By.name("username")).sendKeys(userName);
    webDriver.findElement(By.name("password")).sendKeys(password);
    webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();
  }
}

代码示例来源:origin: spring-io/initializr

public WebElement dependency(String value) {
  for (WebElement element : this.form.findElements(By.name("style"))) {
    if (value.equals(element.getAttribute("value"))) {
      return element;
    }
  }
  throw new AssertionError("Dependency not found: " + value);
}

代码示例来源:origin: cloudfoundry/uaa

private void changePassword(String originalPassword, String newPassword, String confirmPassword) {
  webDriver.findElement(By.xpath("//*[text()='"+userEmail+"']")).click();
  webDriver.findElement(By.linkText("Account Settings")).click();
  webDriver.findElement(By.linkText("Change Password")).click();
  webDriver.findElement(By.name("current_password")).sendKeys(originalPassword);
  webDriver.findElement(By.name("new_password")).sendKeys(newPassword);
  webDriver.findElement(By.name("confirm_password")).sendKeys(confirmPassword);
  webDriver.findElement(By.xpath("//input[@value='Change password']")).click();
}

代码示例来源: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 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

private void navigateToForcePasswordChange() {
  updateUserToForcePasswordChange(restTemplate, baseUrl, adminAccessToken, userId);
  webDriver.get(baseUrl+"/login");
  webDriver.findElement(By.name("username")).sendKeys(userEmail);
  webDriver.findElement(By.name("password")).sendKeys("secr3T");
  webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();
  assertThat(webDriver.findElement(By.cssSelector("h1")).getText(),
    containsString("Force Change Password"));
  assertEquals(baseUrl+"/force_password_change", webDriver.getCurrentUrl());
}

代码示例来源:origin: cloudfoundry/uaa

@Test
public void resettingAPasswordWithInvalidPassword() throws Exception {
  // Go to Forgot Password page
  beginPasswordReset(username);
  String link = getPasswordResetLink(email);
  webDriver.get(link);
  // Enter invalid password information
  webDriver.findElement(By.name("password")).sendKeys("newsecret");
  webDriver.findElement(By.name("password_confirmation")).sendKeys("");
  webDriver.findElement(By.xpath("//input[@value='Create new password']")).click();
  assertThat(webDriver.findElement(By.cssSelector(".error-message")).getText(), containsString("Passwords must match and not be empty."));
}

代码示例来源:origin: cloudfoundry/uaa

@Test
public void testHandleForcePasswordChangeInvalidConfirmation() throws Exception {
  navigateToForcePasswordChange();
  webDriver.findElement(By.name("password")).sendKeys("newsecr3T");
  webDriver.findElement(By.name("password_confirmation")).sendKeys("invalid");
  webDriver.findElement(By.xpath("//input[@value='Create new password']")).click();
  assertEquals(baseUrl+"/force_password_change", webDriver.getCurrentUrl());
  assertThat(webDriver.findElement(By.cssSelector(".error-message")).getText(),
    containsString("Passwords must match and not be empty."));
}

代码示例来源:origin: cloudfoundry/uaa

@Test
public void testHandleForceChangingPasswordWithNewPasswordSameAsOld() throws Exception {
  navigateToForcePasswordChange();
  webDriver.findElement(By.name("password")).sendKeys("secr3T");
  webDriver.findElement(By.name("password_confirmation")).sendKeys("secr3T");
  webDriver.findElement(By.xpath("//input[@value='Create new password']")).click();
  assertEquals(baseUrl+"/force_password_change", webDriver.getCurrentUrl());
  assertThat(webDriver.findElement(By.cssSelector(".error-message")).getText(),
    containsString("Your new password cannot be the same as the old password."));
}

代码示例来源:origin: spring-io/initializr

public HomePage submit() {
  String url = this.driver.getCurrentUrl();
  this.form.findElement(By.name("generate-project")).click();
  assertThat(this.driver.getCurrentUrl()).isEqualTo(url);
  return this;
}

代码示例来源:origin: cloudfoundry/uaa

private void login(IdentityProvider<SamlIdentityProviderDefinition> provider) {
    webDriver.get(baseUrl + "/login");
    Assert.assertEquals("Cloud Foundry", webDriver.getTitle());
    webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).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();
  }
}

代码示例来源:origin: cloudfoundry/uaa

@Test
public void resetPassword_displaysErrorMessage_WhenPasswordIsInvalid() throws Exception {
  String newPassword = new RandomValueStringGenerator(260).generate();
  beginPasswordReset(username);
  String link = getPasswordResetLink(email);
  webDriver.get(link);
  webDriver.findElement(By.name("password")).sendKeys(newPassword);
  webDriver.findElement(By.name("password_confirmation")).sendKeys(newPassword);
  webDriver.findElement(By.xpath("//input[@value='Create new password']")).click();
  assertThat(webDriver.findElement(By.cssSelector(".error-message")).getText(), containsString("Password must be no more than 255 characters in length."));
}

代码示例来源:origin: cloudfoundry/uaa

private void doLogin() throws UnsupportedEncodingException {
  webDriver.get(baseUrl + "/login");
  webDriver.findElement(By.name("username")).sendKeys(testAccounts.getUserName());
  webDriver.findElement(By.name("password")).sendKeys(testAccounts.getPassword());
  webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();
  Cookie currentUserCookie = webDriver.manage().getCookieNamed("Current-User");
  CurrentUserInformation currentUserInformation = JsonUtils.readValue(URLDecoder.decode(currentUserCookie.getValue(), "UTF-8"), CurrentUserInformation.class);
  String userId = currentUserInformation.getUserId();
  testPage = "file://" + System.getProperty("user.dir") + "/src/test/resources/session_frame_test.html#" + userId;
}

代码示例来源:origin: cloudfoundry/uaa

@Before
public void setUp() {
  logout_and_clear_cookies();
  webDriver.get(baseUrl + "/login");
  webDriver.findElement(By.name("username")).sendKeys(testAccounts.getUserName());
  webDriver.findElement(By.name("password")).sendKeys(testAccounts.getPassword());
  webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();
  asOnHomePage = new HomePagePerspective(webDriver, testAccounts.getUserName());
}

代码示例来源: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 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 testHandleForcePasswordChangeEmptyConfirmation() throws Exception {
  navigateToForcePasswordChange();
  webDriver.findElement(By.name("password")).sendKeys("newsecr3T");
  webDriver.findElement(By.xpath("//input[@value='Create new password']")).click();
  assertEquals(baseUrl+"/force_password_change", webDriver.getCurrentUrl());
  assertThat(webDriver.findElement(By.cssSelector(".error-message")).getText(),
    containsString("Passwords must match and not be empty."));
}

代码示例来源: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")));
}

相关文章