Example usage for org.openqa.selenium WebElement getAttribute

List of usage examples for org.openqa.selenium WebElement getAttribute

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement getAttribute.

Prototype

String getAttribute(String name);

Source Link

Document

Get the value of the given attribute of the element.

Usage

From source file:com.coderoad.automation.rocketTruedx.RocketTruedxNaBasePage.java

License:Open Source License

/**
 * Verify phone number validation.//from w  w  w.j a v  a 2  s . co  m
 * 
 * @param xpathInputPhoneNumber the xpath input phone number
 * @param phone the phone
 * @param typeValidation the type validation
 */
public void verifyPhoneNumberValidation(String xpathInputPhoneNumber, String phone, String typeValidation) {

    WaitUtil.waitUntil(3);
    WebElement element = driver.findElement(By.xpath(xpathInputPhoneNumber));
    element.clear();
    element.sendKeys(phone);
    element = driver.findElement(By.xpath(xpathInputPhoneNumber));
    Assert.assertTrue(
            element.getAttribute("aria-invalid").contains(typeValidation.equals("1") ? "false" : "true"),
            "The validation does not function correctly.");
    LogUtil.log("The validation functions correctly.", LogLevel.LOW);
}

From source file:com.cognifide.aet.job.common.modifiers.login.LoginFormComponent.java

License:Apache License

private boolean isFilledProperly(WebElement element, String value) {
    return element.getAttribute(VALUE_ATTRIBUTE).equals(value);
}

From source file:com.cognifide.aet.sanity.functional.cucumber.FilteringSteps.java

License:Apache License

@When("^I search for tests containing \"([^\"]*)\"$")
public void iSearchForTestsContaining(final String searchedTerm) throws Throwable {
    Aside aside = reportHomePage.getAside();
    final WebElement searchInput = aside.getSearchInput();

    // retries typing as there is known bug in selenium:
    // https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/4446
    bobcatWait.withTimeout(Timeouts.MEDIUM).until(new ExpectedCondition<Boolean>() {

        @Nullable/*from w w w. java 2s  .  c  o m*/
        @Override
        public Boolean apply(@Nullable WebDriver input) {
            searchInput.clear();
            searchInput.sendKeys(searchedTerm);
            return searchInput.getAttribute("value").equals(searchedTerm);
        }
    });
}

From source file:com.cognifide.bdd.demo.po.feedback.RichtextComponent.java

License:Apache License

boolean checkIfHasClass(WebElement element, String className) {
    boolean hasClass = false;
    String classAttributeValue = element.getAttribute(HtmlTags.Attributes.CLASS);
    if (classAttributeValue != null) {
        if (className == null || className.isEmpty()) {
            hasClass = true;//from www  .j a v  a 2s . com
        } else {
            String[] cssClasses = classAttributeValue.split(" ");
            hasClass = Arrays.asList(cssClasses).contains(className);
        }
    }
    return hasClass;
}

From source file:com.cognifide.bdd.demo.po.feedback.RichtextComponentTest.java

License:Apache License

@Theory
public void shouldProperlyRecognizeCssClassInWebElement(Object[] dataPoint) throws Exception {
    RichtextComponent testedObject = new RichtextComponent();
    String classAttributeValue = (String) dataPoint[0];
    String checkedClass = (String) dataPoint[1];
    boolean expectedResult = (boolean) dataPoint[2];

    WebElement mockWebElement = mock(WebElement.class);
    when(mockWebElement.getAttribute(eq(HtmlTags.Attributes.CLASS))).thenReturn(classAttributeValue);

    boolean actual = testedObject.checkIfHasClass(mockWebElement, checkedClass);

    String msg = String.format("Should return '%s' for class attribute: '%s' and checked class: '%s'",
            expectedResult, classAttributeValue, checkedClass);
    assertThat(msg, actual, is(expectedResult));
}

From source file:com.cognifide.bdd.demo.po.summer.ImageComponent.java

License:Apache License

public String getImgAttribute(WebElement img, String name) {
    return img.getAttribute(name);
}

From source file:com.cognifide.qa.bb.aem.dialog.classic.field.image.AemImageSetterHelper.java

License:Apache License

private String getImagePlaceholderId(WebElement imagePlaceholder) {
    By grandfatherSelector = By.xpath("../../.");
    WebElement el = imagePlaceholder.findElement(grandfatherSelector);
    return el.getAttribute("id");
}

From source file:com.cognifide.qa.bb.aem.expectedconditions.ContentFinderActions.java

License:Apache License

/**
 * Clicks contentFinder tab and checks if it is active.
 *
 * @param tab tab to be showed/*from w  ww . ja va 2  s .  co m*/
 * @return condition for tab to be active
 */
public static ExpectedCondition<Boolean> showContentFinderTab(final WebElement tab) {
    return new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
            tab.click();
            return tab.getAttribute(HtmlTags.Attributes.CLASS).contains(TAB_ACTIVE);
        }

        @Override
        public String toString() {
            return "Tab is not ready";
        }
    };
}

From source file:com.cognifide.qa.bb.aem.expectedconditions.SidekickActions.java

License:Apache License

/**
 * Checks if section in sidekick is expanded based on section WebElement
 *
 * @param section tested for expansion/*from  w  w  w .  j av  a  2  s. co m*/
 * @return true if sections is expanded, false if section is collapsed
 */
public static boolean isSectionExpanded(WebElement section) {
    boolean isExpanded = false;
    if (!section.getAttribute(HtmlTags.Attributes.CLASS).contains(COLLAPSED_CLASS)) {
        isExpanded = true;
    }
    return isExpanded;
}

From source file:com.cognifide.qa.bb.aem.expectedconditions.SidekickActions.java

License:Apache License

/**
 * Checks if fieldset in sidekick is expanded based on fieldset WebElement
 *
 * @param fieldset tested for expansion// ww  w  .  j  av  a2 s .  c  o m
 * @return true if sections is expanded, false if section is collapsed
 */
public static boolean isFieldsetExpanded(WebElement fieldset) {
    boolean isExpanded = false;
    if (!fieldset.getAttribute(HtmlTags.Attributes.CLASS).contains(COLLAPSED_CLASS)) {
        isExpanded = true;
    }
    return isExpanded;
}