本文整理了Java中org.openqa.selenium.By.className()
方法的一些代码示例,展示了By.className()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。By.className()
方法的具体详情如下:
包路径:org.openqa.selenium.By
类名称:By
方法名:className
[英]Find elements based on the value of the "class" attribute. If an element has multiple classes, then this will match against each of them. For example, if the value is "one two onone", then the class names "one" and "two" will match.
[中]根据“class”属性的值查找元素。如果一个元素有多个类,那么这将与每个类匹配。例如,如果值为“one-two-onone”,则类名“one”和“two”将匹配。
代码示例来源:origin: selenide/selenide
/**
* @see By#className(java.lang.String)
* @since 3.8
*/
public static By byClassName(String className) {
return By.className(className);
}
}
代码示例来源: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
@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 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 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: 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 testChangePassword() throws Exception {
webDriver.get(baseUrl + "/change_password");
signIn(userEmail, PASSWORD);
changePassword(PASSWORD, NEW_PASSWORD, "new");
WebElement errorMessage = webDriver.findElement(By.className("error-message"));
assertTrue(errorMessage.isDisplayed());
assertEquals("Passwords must match and not be empty.", errorMessage.getText());
changePassword(PASSWORD, NEW_PASSWORD, NEW_PASSWORD);
signOut();
signIn(userEmail, NEW_PASSWORD);
}
代码示例来源:origin: TEAMMATES/teammates
/**
* Returns number of question edit forms + question add form.
*/
public int getNumberOfQuestionEditForms() {
return browser.driver.findElements(By.className("questionTable")).size();
}
代码示例来源:origin: TEAMMATES/teammates
private void waitForModalShown() {
// Possible exploration: Change to listening to modal shown event as
// this is based on the implementation detail assumption that once modal-backdrop is added the modal is shown
waitForElementVisibility(By.className("modal-backdrop"));
}
代码示例来源:origin: TEAMMATES/teammates
public void closeCommentModal(String commentId) {
WebElement commentModal = browser.driver.findElement(By.id("commentModal" + commentId));
WebElement modalFooter = commentModal.findElement(By.className("modal-footer"));
WebElement closeButton = modalFooter.findElement(By.className("commentModalClose"));
clickDismissModalButtonAndWaitForModalHidden(closeButton);
}
代码示例来源:origin: TEAMMATES/teammates
private int getStudentRowId(String studentName) {
int studentCount = browser.driver.findElements(By.className("student_row")).size();
for (int i = 0; i < studentCount; i++) {
String studentNameInRow = getStudentNameInRow(i);
if (studentNameInRow.equals(studentName)) {
return i;
}
}
return -1;
}
代码示例来源: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");
}
代码示例来源:origin: TEAMMATES/teammates
public void waitForAjaxLoadCoursesError() {
By element = By.id("retryAjax");
waitForElementPresence(element);
WebElement statusMessage =
browser.driver.findElement(By.id("statusMessagesToUser")).findElement(By.className("statusMessage"));
assertEquals("Courses could not be loaded. Click here to retry.", statusMessage.getText());
}
代码示例来源:origin: TEAMMATES/teammates
/**
* Returns the number of rows from the nth(0-index-based) table
* (which is of type {@code class=table}) in the page.
*/
public int getNumberOfRowsFromDataTable(int tableNum) {
WebElement tableElement = browser.driver.findElements(By.className("table")).get(tableNum);
return tableElement.findElements(By.tagName("tr")).size();
}
代码示例来源:origin: TEAMMATES/teammates
public InstructorCourseEnrollPage loadEnrollLink(String courseId) {
int courseRowNumber = getRowNumberOfCourse(courseId);
return goToLinkInRow(
By.className("t_course_enroll" + courseRowNumber),
InstructorCourseEnrollPage.class);
}
代码示例来源:origin: TEAMMATES/teammates
public InstructorCourseEditPage loadEditLink(String courseId) {
int courseRowNumber = getRowNumberOfCourse(courseId);
return goToLinkInRow(
By.className("t_course_edit" + courseRowNumber),
InstructorCourseEditPage.class);
}
代码示例来源:origin: TEAMMATES/teammates
/**
* Waits for a confirmation modal to appear and click the cancel button.
*/
public void waitForConfirmationModalAndClickCancel() {
waitForModalShown();
WebElement cancelButton = browser.driver.findElement(By.className("modal-btn-cancel"));
waitForElementToBeClickable(cancelButton);
clickDismissModalButtonAndWaitForModalHidden(cancelButton);
}
代码示例来源:origin: TEAMMATES/teammates
/**
* Returns the value of the header located at {@code (row, column)}
* from the nth(0-index-based) table (which is of type {@code class=table}) in the page.
*/
public String getHeaderValueFromDataTable(int tableNum, int row, int column) {
WebElement tableElement = browser.driver.findElements(By.className("table")).get(tableNum);
WebElement trElement = tableElement.findElements(By.tagName("tr")).get(row);
WebElement tdElement = trElement.findElements(By.tagName("th")).get(column);
return tdElement.getText();
}
代码示例来源:origin: TEAMMATES/teammates
public void clickCommentModalButton(String commentId) {
WebElement commentModal = browser.driver.findElement(By.id("commentModal" + commentId));
WebElement parentTable = commentModal.findElement(By.xpath("../.."));
WebElement commentButton = parentTable.findElement(By.className("comment-button"));
click(commentButton);
}
代码示例来源:origin: TEAMMATES/teammates
/**
* Returns the number of columns from the header in the table
* (which is of type {@code class=table}) in the page.
*/
public int getNumberOfColumnsFromDataTable(int tableNum) {
WebElement tableElement = browser.driver.findElements(By.className("table")).get(tableNum);
WebElement trElement = tableElement.findElement(By.tagName("tr"));
return trElement.findElements(By.tagName("th")).size();
}
内容来源于网络,如有侵权,请联系作者删除!