org.openqa.selenium.By#className ( )源码实例Demo

下面列出了org.openqa.selenium.By#className ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Gets the By locator through reading the object repository.
 * @param key Is in the form of HomePage.LoginLink or ${pageName}.${elementName}
 * @return A By locator that can be used to locate WebElement(s).
 */
public By getByFromObjectRepositoryLocator(String key) {
    By by = null;
    String locatorType = getLocatorTypeString(key);
    String locatorString = getLocatorValueString(key);
    if(locatorType != null && locatorString != null) {
        if(locatorType.equalsIgnoreCase("LINK_TEXT")) {
            by = By.linkText(locatorString);
        } else if (locatorType.equalsIgnoreCase("PARTIAL_LINK_TEXT")) {
            by = By.partialLinkText(locatorString);
        } else if (locatorType.equalsIgnoreCase("NAME")) {
            by = By.name(locatorString);
        } else if (locatorType.equalsIgnoreCase("ID")) {
            by = By.id(locatorString);
        } else if (locatorType.equalsIgnoreCase("CLASS_NAME")) {
            by = By.className(locatorString);
        } else if (locatorType.equalsIgnoreCase("TAG_NAME")) {
            by = By.tagName(locatorString);
        } else if (locatorType.equalsIgnoreCase("CSS_SELECTOR")) {
            by = By.cssSelector(locatorString);
        } else if (locatorType.equalsIgnoreCase("XPATH")) {
            by = By.xpath(locatorString);
        }
    }
    return by;
}
 
源代码2 项目: bromium   文件: ClickClassByText.java
@Override
public void executeAfterJSPreconditionHasBeenSatisfied(WebDriver driver,
                                                       ReplayingState state,
                                                       Function<SearchContext, SearchContext> contextProvider) {
    By elementsLocator = By.className(initialCollectorClass);
    List<WebElement> webElements = contextProvider.apply(driver).findElements(elementsLocator);

    Optional<WebElement> webElementOptional = webElements.stream()
            .filter(this::elementTextIsEqualToAndIsDisplayed)
            .findFirst();

    if (!webElementOptional.isPresent()) {
        throw new ElementNotSelectableException("Element with class "
                + initialCollectorClass
                + " and text " + text + " was not found" );
    }

    webElementOptional.get().click();
}
 
源代码3 项目: bromium   文件: ClickClassByTextTest.java
@Test
public void throwsExceptionIfNoSuitableElementsAreFound() {
    WebElement incorrectWebElement = mock(WebElement.class);
    when(incorrectWebElement.getText()).thenReturn("sometATPhing");
    when(incorrectWebElement.isDisplayed()).thenReturn(true);

    List<WebElement> webElements = new ArrayList<>();
    webElements.add(incorrectWebElement);

    By elementsLocator = By.className(initialCollectorClass);
    WebDriver webDriver = mock(WebDriver.class);
    when(webDriver.findElements(elementsLocator)).thenReturn(webElements);

    SearchContextFunction contextProvider = webDriver1 -> webDriver;
    ClickClassByText clickClassByText = new ClickClassByText(initialCollectorClass, text, expectsHttp, contextProvider);
    thrown.expect(ElementNotSelectableException.class);
    clickClassByText.executeAfterJSPreconditionHasBeenSatisfied(webDriver, mock(ReplayingState.class), contextProvider);
}
 
源代码4 项目: demo-java   文件: StepDefinitions.java
@When("^I add (\\d+) items? to the cart$")
public void add_items_to_cart(int items){
    By itemButton = By.className("btn_primary");

    IntStream.range(0, items).forEach(i -> {
        wait.until(ExpectedConditions.elementToBeClickable(getDriver().findElement(itemButton)));
        getDriver().findElement(itemButton).click();
    });
}
 
源代码5 项目: cerberus-source   文件: WebDriverService.java
private By getBy(Identifier identifier) {

        LOG.debug("Finding selenium Element : " + identifier.getLocator() + " by : " + identifier.getIdentifier());

        if (identifier.getIdentifier().equalsIgnoreCase("id")) {
            return By.id(identifier.getLocator());

        } else if (identifier.getIdentifier().equalsIgnoreCase("name")) {
            return By.name(identifier.getLocator());

        } else if (identifier.getIdentifier().equalsIgnoreCase("class")) {
            return By.className(identifier.getLocator());

        } else if (identifier.getIdentifier().equalsIgnoreCase("css")) {
            return By.cssSelector(identifier.getLocator());

        } else if (identifier.getIdentifier().equalsIgnoreCase("xpath")) {
            return By.xpath(identifier.getLocator());

        } else if (identifier.getIdentifier().equalsIgnoreCase("link")) {
            return By.linkText(identifier.getLocator());

        } else if (identifier.getIdentifier().equalsIgnoreCase("data-cerberus")) {
            return By.xpath("//*[@data-cerberus='" + identifier.getLocator() + "']");

        } else {
            throw new NoSuchElementException(identifier.getIdentifier());
        }
    }
 
源代码6 项目: bromium   文件: ClickClassByTextTest.java
@Test
public void throwsExceptionIfNoElementsAreFound() {
    List<WebElement> webElements = new ArrayList<>();

    By elementsLocator = By.className(initialCollectorClass);
    WebDriver webDriver = mock(WebDriver.class);
    when(webDriver.findElements(elementsLocator)).thenReturn(webElements);

    SearchContextFunction contextProvider = webDriver1 -> webDriver;
    ClickClassByText clickClassByText = new ClickClassByText(initialCollectorClass, text, expectsHttp, contextProvider);
    thrown.expect(ElementNotSelectableException.class);
    clickClassByText.executeAfterJSPreconditionHasBeenSatisfied(webDriver, mock(ReplayingState.class), contextProvider);
}
 
源代码7 项目: selenium   文件: AbstractFindByBuilder.java
protected By buildByFromShortFindBy(FindBy findBy) {
  if (!"".equals(findBy.className())) {
    return By.className(findBy.className());
  }

  if (!"".equals(findBy.css())) {
    return By.cssSelector(findBy.css());
  }

  if (!"".equals(findBy.id())) {
    return By.id(findBy.id());
  }

  if (!"".equals(findBy.linkText())) {
    return By.linkText(findBy.linkText());
  }

  if (!"".equals(findBy.name())) {
    return By.name(findBy.name());
  }

  if (!"".equals(findBy.partialLinkText())) {
    return By.partialLinkText(findBy.partialLinkText());
  }

  if (!"".equals(findBy.tagName())) {
    return By.tagName(findBy.tagName());
  }

  if (!"".equals(findBy.xpath())) {
    return By.xpath(findBy.xpath());
  }

  // Fall through
  return null;
}
 
public ProductTabContentForm() {
    super(By.className("tab-content"), "Product tab content");
}
 
源代码9 项目: functional-tests-core   文件: Locators.java
public By switchLocator() {
    return By.className(this.uiElementClass.switchLocator());
}
 
@Override
public By getBy()
{
	return By.className(getValue());
}
 
源代码11 项目: functional-tests-core   文件: Locators.java
public By navigationBarLocator() {
    return By.className(this.uiElementClass.navigationBarLocator());
}
 
源代码12 项目: functional-tests-core   文件: Locators.java
public By webViewLocator() {
    return By.className(this.uiElementClass.webViewLocator());
}
 
源代码13 项目: functional-tests-core   文件: Locators.java
public By frameLayoutLocator() {
    return By.className(this.uiElementClass.frameLayoutLocator());
}
 
源代码14 项目: functional-tests-core   文件: Locators.java
public By tabHostLocator() {
    return By.className(this.uiElementClass.tabHostLocator());
}
 
源代码15 项目: functional-tests-core   文件: Locators.java
public By buttonLocator() {
    return By.className(this.uiElementClass.buttonLocator());
}
 
源代码16 项目: functional-tests-core   文件: Locators.java
public By tabWidgetLocator() {
    return By.className(this.uiElementClass.tabWidgetLocator());
}
 
源代码17 项目: functional-tests-core   文件: Locators.java
public By textViewLocator() {
    return By.className(this.uiElementClass.textViewLocator());
}
 
源代码18 项目: teammates   文件: InstructorFeedbackEditPage.java
private String getDatepickerMonth() {
    By by = By.className("ui-datepicker-month");
    waitForElementPresence(by);
    return browser.driver.findElement(by).getText();
}
 
源代码19 项目: functional-tests-core   文件: Locators.java
public By imageLocator() {
    return By.className(this.uiElementClass.imageLocator());
}
 
源代码20 项目: functional-tests-core   文件: Locators.java
public By imageButtonLocator() {
    return By.className(this.uiElementClass.imageButtonLocator());
}