本文整理了Java中org.openqa.selenium.By
类的一些代码示例,展示了By
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。By
类的具体详情如下:
包路径:org.openqa.selenium.By
类名称:By
[英]Mechanism used to locate elements within a document. In order to create your own locating mechanisms, it is possible to subclass this class and override the protected methods as required, though it is expected that all subclasses rely on the basic finding mechanisms provided through static methods of this class: public WebElement findElement(WebDriver driver) { WebElement element = driver.findElement(By.id(getSelector())); if (element == null) element = driver.findElement(By.name(getSelector()); return element; }
[中]用于在文档中定位元素的机制。为了创建您自己的定位机制,可以根据需要对该类进行子类化并重写受保护的方法,尽管预期所有子类都依赖于通过此类的静态方法提供的基本查找机制:public WebElement findElement(WebDriver driver) { WebElement element = driver.findElement(By.id(getSelector())); if (element == null) element = driver.findElement(By.name(getSelector()); return element; }
代码示例来源:origin: cloudfoundry/uaa
@Test
public void testFrameReportsChangedWhenSameUser_whenLoggedOut() throws UnsupportedEncodingException, InterruptedException {
webDriver.get(testPage);
webDriver.findElement(By.id("sameUser")).click();
assertMessage("unchanged");
}
代码示例来源: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
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 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 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: spring-io/initializr
public void advanced() {
this.form.findElement(By.cssSelector(".tofullversion"))
.findElement(By.tagName("a")).click();
}
代码示例来源: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
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: cloudfoundry/uaa
@Test
public void testAccountChooserFlow() throws Exception {
String zoneUrl = createDiscoveryZone();
String userEmail = createAnotherUser(zoneUrl);
webDriver.get(zoneUrl + "/logout.do");
webDriver.get(zoneUrl);
loginThroughDiscovery(userEmail, USER_PASSWORD);
webDriver.get(zoneUrl + "/logout.do");
webDriver.get(zoneUrl);
assertEquals(userEmail, webDriver.findElement(By.className("email-address")).getText());
webDriver.findElement(By.className("email-address")).click();
assertEquals(userEmail, webDriver.findElement(By.id("username")).getAttribute("value"));
webDriver.findElement(By.id("password")).sendKeys(USER_PASSWORD);
webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();
assertEquals("Where to?", webDriver.findElement(By.cssSelector(".island h1")).getText());
}
代码示例来源: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: TEAMMATES/teammates
public void clickVisibilityOptionForResponseCommentAndSave(String idString, int numOfTheCheckbox) {
String idSuffix = idString.substring(18);
WebElement commentRow = browser.driver.findElement(By.id(idString));
click(commentRow.findElements(By.tagName("a")).get(1));
WebElement commentEditForm = browser.driver.findElement(By.id("responseCommentEditForm" + idSuffix));
click(commentRow.findElement(By.id("frComment-visibility-options-trigger" + idSuffix)));
click(commentRow.findElements(By.cssSelector("input[type='checkbox']")).get(numOfTheCheckbox));
click(commentEditForm.findElement(By.className("col-sm-offset-5")).findElement(By.tagName("a")));
ThreadHelper.waitFor(1000);
}
代码示例来源: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 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
@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());
}
代码示例来源:origin: cloudfoundry/uaa
@Test
public void testLoginHint() throws Exception {
String newUserEmail = createAnotherUser();
webDriver.get(baseUrl + "/logout.do");
String ldapLoginHint = URLEncoder.encode("{\"origin\":\"ldap\"}", "UTF-8");
webDriver.get(baseUrl + "/login?login_hint=" + ldapLoginHint);
assertEquals("Cloud Foundry", webDriver.getTitle());
attemptLogin(newUserEmail, USER_PASSWORD);
assertThat(webDriver.findElement(By.className("alert-error")).getText(), containsString("Unable to verify email or password. Please try again."));
String uaaLoginHint = URLEncoder.encode("{\"origin\":\"uaa\"}", "UTF-8");
webDriver.get(baseUrl + "/login?login_hint=" + uaaLoginHint);
assertEquals("Cloud Foundry", webDriver.getTitle());
attemptLogin(newUserEmail, USER_PASSWORD);
assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to?"));
webDriver.get(baseUrl + "/logout.do");
}
代码示例来源: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: TEAMMATES/teammates
public boolean isVisibilityDropdownOptionHidden(String optionValue, int qnNumber) {
return browser.driver.findElement(By.id("questionTable-" + qnNumber))
.findElement(By.className("visibility-options-dropdown-option"))
.findElement(By.xpath("//a[@data-option-name='" + optionValue + "']/.."))
.getAttribute("class").contains("hidden");
}
内容来源于网络,如有侵权,请联系作者删除!