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

x33g5p2x  于2022-02-02 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(139)

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

WebDriver.findElements介绍

[英]Find all elements within the current page using the given mechanism. This method is affected by the 'implicit wait' times in force at the time of execution. When implicitly waiting, this method will return as soon as there are more than 0 items in the found collection, or will return an empty list if the timeout is reached.
[中]使用给定的机制查找当前页面中的所有元素。此方法受执行时有效的“隐式等待”时间的影响。当隐式等待时,只要找到的集合中有超过0个项,此方法就会返回,或者如果达到超时,则返回空列表。

代码示例

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

@Test
public void testAmountOfJavascriptTests() {
  webDriver.get(testPage);
  assertEquals(4, webDriver.findElements(By.cssSelector("#testLinks li")).size());
}

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

@Test
public void testAccountChooserPopulatesUsernameNotEmailWhenOriginIsUAAorLDAP() throws Exception {
  String userUAA = "{\"userId\":\"1\",\"username\":\"userUAA\",\"origin\":\"uaa\",\"email\":\"user@uaa.org\"}";
  String userLDAP = "{\"userId\":\"2\",\"username\":\"userLDAP\",\"origin\":\"ldap\",\"email\":\"user@ldap.org\"}";
  String userExternal = "{\"userId\":\"3\",\"username\":\"userExternal\",\"origin\":\"external\",\"email\":\"user@external.org\"}";
  String zoneUrl = createDiscoveryZone();
  webDriver.get(zoneUrl);
  webDriver.manage().deleteAllCookies();
  JavascriptExecutor js = (JavascriptExecutor) webDriver;
  js.executeScript("document.cookie = \"Saved-Account-1=" + URLEncoder.encode(userUAA, StandardCharsets.UTF_8.name()) + ";path=/;domain=testzone3.localhost\"");
  js.executeScript("document.cookie = \"Saved-Account-2=" + URLEncoder.encode(userLDAP, StandardCharsets.UTF_8.name()) + ";path=/;domain=testzone3.localhost\"");
  js.executeScript("document.cookie = \"Saved-Account-3=" + URLEncoder.encode(userExternal, StandardCharsets.UTF_8.name()) + ";path=/;domain=testzone3.localhost\"");
  webDriver.navigate().refresh();
  assertEquals(3, webDriver.findElements(By.cssSelector("span.email-address")).size());
  webDriver.findElement(By.xpath("//span[contains(text(), 'userUAA')]")).click();
  assertEquals("userUAA", webDriver.findElement(By.id("username")).getAttribute("value"));
  webDriver.navigate().back();
  webDriver.findElement(By.xpath("//span[contains(text(), 'userLDAP')]")).click();
  assertEquals("userLDAP", webDriver.findElement(By.id("username")).getAttribute("value"));
  webDriver.navigate().back();
  webDriver.findElement(By.xpath("//span[contains(text(), 'userExternal')]")).click();
  assertEquals("user@external.org", webDriver.findElement(By.id("username")).getAttribute("value"));
  webDriver.manage().deleteAllCookies();
}

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

Assert.assertThat(webDriver.findElements(By.xpath("//input[@value='app-password.write']")), Matchers.empty());

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

.findElements(By.xpath("//a[text()='" + samlIdentityProviderDefinition.getLinkText() + "']"));
assertNotNull(elements);
assertEquals(1, elements.size());

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

.findElements(By.xpath("//a[text()='" + samlIdentityProviderDefinition.getLinkText() + "']"));
assertNotNull(elements);
assertEquals(1, elements.size());
assertEquals(zone.getName(), webDriver.getTitle());
elements = webDriver
    .findElements(By.xpath("//a[text()='" + samlIdentityProviderDefinition.getLinkText() + "']"));
assertNotNull(elements);
assertEquals(0, elements.size());
assertEquals(zone.getName(), webDriver.getTitle());
elements = webDriver
    .findElements(By.xpath("//a[text()='" + samlIdentityProviderDefinition.getLinkText() + "']"));
assertNotNull(elements);
assertEquals(1, elements.size());

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

@Test
public void testBannerBackgroundIsHiddenIfNoTextOrImage() {
  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.setLink("http://example.com");
  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(0, webDriver.findElements(By.cssSelector(".banner-header")).size());
}

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

Assert.assertEquals(zone.getName(), webDriver.getTitle());
List<WebElement> elements = webDriver.findElements(By.xpath("//a[text()='"+ samlIdentityProviderDefinition.getLinkText()+"']"));
assertNotNull(elements);
assertEquals(2, elements.size());
webDriver.get(testZone1Url + "/login");
Assert.assertEquals(zone.getName(), webDriver.getTitle());
elements = webDriver.findElements(By.xpath("//a[text()='"+ samlIdentityProviderDefinition.getLinkText()+"']"));
assertNotNull(elements);
assertEquals(1, elements.size());
webDriver.get(testZone1Url + "/login");
Assert.assertEquals(zone.getName(), webDriver.getTitle());
elements = webDriver.findElements(By.xpath("//a[text()='"+ samlIdentityProviderDefinition.getLinkText()+"']"));
assertNotNull(elements);
assertEquals(2, elements.size());

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

assertNotNull(idp.getId());
List<WebElement> elements = webDriver.findElements(By.xpath("//a[text()='" + samlIdentityProviderDefinition.getLinkText() + "']"));
assertNotNull(elements);
assertEquals(1, elements.size());
webDriver.get(url);
String errorMessage = "No Supported binding was found for SAML SSO profile - browser. Supported SAML SSO browser profile bindings are HTTP-POST and HTTP-Redirect.";
elements = webDriver.findElements(By.xpath("//p[text()='" + errorMessage + "']"));
assertNotNull(elements);
assertEquals(1, elements.size());

代码示例来源:origin: TEAMMATES/teammates

/**
 * Returns the id of the table
 *         (which is of type {@code class=table}) in the page.
 */
public String getDataTableId(int tableNum) {
  WebElement tableElement = browser.driver.findElements(By.className("table")).get(tableNum);
  return tableElement.getAttribute("id");
}

代码示例来源:origin: TEAMMATES/teammates

private int getCourseNumber(String courseId) {
  int id = -1;
  List<WebElement> panels = browser.driver.findElements(By.className("panel-heading"));
  for (WebElement panel : panels) {
    if (panel.getText().startsWith("[" + courseId + "]")) {
      break;
    }
    id++;
  }
  return id;
}

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

webDriver.get(spZoneUrl + "/login");
assertEquals(spZone.getName(), webDriver.getTitle());
List<WebElement> elements = webDriver.findElements(By.xpath("//a[text()='" + samlIdentityProviderDefinition.getLinkText() + "']"));
assertNotNull(elements);
assertEquals(0, elements.size());
assertEquals(spZone.getName(), webDriver.getTitle());
elements = webDriver
  .findElements(By.xpath("//a[text()='" + samlIdentityProviderDefinition.getLinkText() + "']"));
assertNotNull(elements);
assertEquals(1, elements.size());

代码示例来源:origin: TEAMMATES/teammates

public boolean isAllFeedbackPathOptionsEnabledForNewQuestion() {
  List<WebElement> options = browser.driver.findElements(By.cssSelector("#givertype-" + NEW_QUESTION_NUM + " option"));
  options.addAll(browser.driver.findElements(By.cssSelector("#recipienttype-" + NEW_QUESTION_NUM + " option")));
  for (WebElement option : options) {
    if (!option.isEnabled()) {
      return false;
    }
  }
  return true;
}

代码示例来源: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 verifyAllStatsVisibility() {
  for (WebElement e : browser.driver.findElements(By.className("resultStatistics"))) {
    if ("none".equals(e.getCssValue("display"))) {
      return false;
    }
  }
  return true;
}

代码示例来源: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 void waitForSectionStudentPanelsToCollapse() {
  List<WebElement> studentPanels = browser.driver.findElements(
      By.cssSelector("#panelBodyCollapse-section-0-1 .panel-collapse"));
  waitForElementsToDisappear(studentPanels);
}

代码示例来源:origin: TEAMMATES/teammates

public String getStudentRowId(String courseId, String studentName) {
  int courseNumber = getCourseNumber(courseId);
  int studentCount = browser.driver.findElements(By.cssSelector("tr[id^='student-c" + courseNumber + "']"))
                   .size();
  for (int i = 0; i < studentCount; i++) {
    String studentNameInRow = getStudentNameInRow(courseNumber, i);
    if (studentNameInRow.equals(studentName)) {
      return courseNumber + "." + i;
    }
  }
  return "";
}

代码示例来源:origin: TEAMMATES/teammates

/**
 * Returns the value of the cell located at {@code (row, column)}
 *         from the nth(0-index-based) table (which is of type {@code class=table}) in the page.
 */
public String getCellValueFromDataTable(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("td")).get(column);
  return tdElement.getText();
}

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

/**
 * 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();
}

相关文章