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

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

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

By.xpath介绍

暂无

代码示例

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

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

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

@Override
 public SelenideElement execute(SelenideElement proxy, WebElementSource locator, Object[] args) {
  String tagOrClass = (String) args[0];
  String xpath = tagOrClass.startsWith(".") ?
    format("ancestor::*[contains(concat(' ', normalize-space(@class), ' '), ' %s ')][1]", tagOrClass.substring(1)) :
    format("ancestor::%s[1]", tagOrClass);
  return locator.find(proxy, By.xpath(xpath), 0);
 }
}

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

private void loginThroughDiscovery(String userEmail, String password) {
    webDriver.findElement(By.id("email")).sendKeys(userEmail);
    webDriver.findElement(By.cssSelector(".form-group input[value='Next']")).click();
    webDriver.findElement(By.id("password")).sendKeys(password);
    webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();
  }
}

代码示例来源:origin: galenframework/galen

private static By convertToBy(Locator locator) {
    if ("xpath".equals(locator.getLocatorType())) {
      return By.xpath(locator.getLocatorValue());
    }
    else if ("id".equals(locator.getLocatorType())) {
      return By.id(locator.getLocatorValue());
    }
    else if ("css".equals(locator.getLocatorType())) {
      return By.cssSelector(locator.getLocatorValue());
    }
    else return null;
  }
}

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

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 resetPassword_displaysErrorMessage_NewPasswordSameAsOld() throws Exception {
  beginPasswordReset(username);
  String link = getPasswordResetLink(email);
  webDriver.get(link);
  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();
  assertThat(webDriver.findElement(By.cssSelector(".error-message")).getText(), containsString("Your new password cannot be the same as the old password."));
}

代码示例来源: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 testHandleForceChangingPassword() throws Exception {
  navigateToForcePasswordChange();
  webDriver.findElement(By.name("password")).sendKeys("newsecr3T");
  webDriver.findElement(By.name("password_confirmation")).sendKeys("newsecr3T");
  webDriver.findElement(By.xpath("//input[@value='Create new password']")).click();
  assertEquals(baseUrl+"/", webDriver.getCurrentUrl());
}

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

@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: 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

@Test
public void testForcePasswordChangeThatFailsPasswordPolicy() {
  navigateToForcePasswordChange();
  String invalidNewPassword = new RandomValueStringGenerator(256).generate();
  webDriver.findElement(By.name("password")).sendKeys(invalidNewPassword);
  webDriver.findElement(By.name("password_confirmation")).sendKeys(invalidNewPassword);
  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("Password must be no more than 255 characters in length."));
}

相关文章