Example usage for org.openqa.selenium By className

List of usage examples for org.openqa.selenium By className

Introduction

In this page you can find the example usage for org.openqa.selenium By className.

Prototype

public static By className(String className) 

Source Link

Document

Find elements based on the value of the "class" attribute.

Usage

From source file:com.cognifide.qa.bb.aem.ui.AemDialog.java

License:Apache License

/**
 * Finds the dialog tab by its index and returns its name (label).
 *
 * @param index of the tab (starts from 0)
 * @return Tab's label./*from   w  ww  . j  a v a  2s. c  o m*/
 */
public String getLabelFromTab(int index) {
    WebElement dialog = webDriver.findElement(DIALOG_XPATH_COMPILED);
    List<WebElement> items = dialog.findElements(By.className("x-tab-item"));
    WebElement widget = items.get(index);
    WebElement label = widget.findElement(By.xpath(".//label"));
    return label.getText();
}

From source file:com.cognifide.qa.bb.aem.ui.sidekick.AemSidekick.java

License:Apache License

/**
 * Finds the icon element associated with the selected tab and clicks it.
 *
 * @param tab sidekick tab name//from  w  w w  .  ja  va 2 s  . c  o  m
 * @return This AemSidekick instance.
 */
public AemSidekick clickTab(SidekickTab tab) {
    final By locator = By.className(AEM_SIDEKICK_TAB_ICON_PARTIAL_CLASS + tab.getTabName());
    final WebElement element = driver.findElement(locator);
    bobcatWait.withTimeout(Timeouts.SMALL).until(SidekickActions.showSidekickTab(element));
    return this;
}

From source file:com.cognifide.qa.bb.aem.ui.wcm.windows.CreatePageWindow.java

License:Apache License

/**
 * @return list of available template names
 *///  w  w w  .ja  v  a 2  s  .c  o m
public List<String> getTemplatesNames() {
    List<String> names = new ArrayList<>();
    for (WebElement template : templatesList) {
        names.add(template.findElement(By.className("template-title")).getText());
    }
    return names;
}

From source file:com.cognifide.qa.bb.test.expectedconditions.CommonExpectedConditionsTest.java

License:Apache License

@Test
public void shouldAnswerTrueWhenScopedElementDoesNotContainElement() {
    //given//from  ww  w . j  av a 2 s. co m
    WebElement element = webDriver.findElement(By.className(EMTPY_CONTAINER_CSS_CLASS));
    By by = By.tagName(PRESENT_TAG);

    //when
    boolean actual = waitFor(CommonExpectedConditions.scopedElementLocatedByNotPresent(element, by));

    //then
    assertThat(actual).as("check if element does not contain element").isTrue();
}

From source file:com.cognifide.qa.bb.test.expectedconditions.CommonExpectedConditionsTest.java

License:Apache License

@Test
public void shouldThrowExceptionWhenScopedElementContainsElement() {
    //given/* w w  w  .  j  a va 2  s.c om*/
    exception.expect(TimeoutException.class);
    WebElement element = webDriver.findElement(By.className(CONTAINER_CSS_CLASS));
    By by = By.tagName(PRESENT_TAG);

    //when
    waitFor(CommonExpectedConditions.scopedElementLocatedByNotPresent(element, by));
}

From source file:com.cognifide.qa.bb.test.expectedconditions.CommonExpectedConditionsTest.java

License:Apache License

@Test
public void shouldAnswerTrueWhenElementIsHidden() {
    //given/*www.j  a v a 2  s .co  m*/
    By by = By.className(HIDDEN_CONTAINER_CSS_CLASS);

    //when
    boolean actual = waitFor(CommonExpectedConditions.elementNotPresentOrVisible(by));

    //then
    assertThat(actual).as("check if element is hidden").isTrue();
}

From source file:com.cognifide.qa.bb.test.expectedconditions.CommonExpectedConditionsTest.java

License:Apache License

@Test
public void shouldThrowExceptionWhenElementIsNotHidden() {
    //given/*w  w  w. j av  a2 s. c  om*/
    exception.expect(TimeoutException.class);
    By by = By.className(CONTAINER_CSS_CLASS);

    //when
    waitFor(CommonExpectedConditions.elementNotPresentOrVisible(by));
}

From source file:com.comcast.dawg.house.AdvanceFilterNavigator.java

License:Apache License

/**
 * Checks if the given condition checks are in the condition list
 * @param conditions The conditions to look through
 * @param conditionTexts The texts to check if they exist
 * @param checked True if all the given conditions are checked
 *//*from  w  ww  .  j ava 2  s .c  o  m*/
public void verifyConditions(List<WebElement> conditions, String[] conditionTexts, boolean checked) {
    for (String c : conditionTexts) {
        WebElement found = getCondition(conditions, c);
        Assert.assertNotNull(found);

        WebElement conditionCheckBox = found.findElement(By.className(IndexPage.CONDITION_CHECK_BOX));
        Assert.assertEquals(conditionCheckBox.getAttribute("checked") != null, checked);
    }
}

From source file:com.comcast.dawg.house.AdvanceFilterNavigator.java

License:Apache License

public void checkConditions(boolean check, String... conditionTexts) {
    WebElement conditionList = driver.findElementByClassName(IndexPage.CONDITION_LIST);
    List<WebElement> conditions = conditionList.findElements(By.tagName("div"));

    for (String conditionText : conditionTexts) {
        WebElement condition = getCondition(conditions, conditionText, true);
        WebElement conditionCheckBox = condition.findElement(By.className(IndexPage.CONDITION_CHECK_BOX));
        if (conditionCheckBox.isSelected() != check) {
            conditionCheckBox.click();//  w  ww  .java 2 s  . c  o  m
        }
    }
}

From source file:com.comcast.dawg.house.AdvanceFilterNavigator.java

License:Apache License

public WebElement getCondition(List<WebElement> conditions, String conditionText, boolean failOnNull) {
    WebElement found = null;/*from w w w  .java 2 s.  c o  m*/
    for (WebElement condition : conditions) {
        if (condition.findElement(By.className(IndexPage.CONDITION_TEXT)).getText().equals(conditionText)) {
            found = condition;
            break;
        }
    }
    if (failOnNull && (found == null)) {

        Collection<String> possibleConditions = new ArrayList<String>();
        for (WebElement condition : conditions) {
            possibleConditions.add(condition.findElement(By.className(IndexPage.CONDITION_TEXT)).getText());
        }

        Assert.fail("Could not find a condition for text '" + conditionText + "' possible values are : "
                + StringUtils.join(possibleConditions, ", "));
    }
    return found;
}