com.codeborne.selenide.Condition [src]

Conditions are used in should / shouldNot / waitUntil / waitWhile constructs. We recommend to import corresponding conditions statically to receive all the advantages of readable code:

static import example static import quick fix example

  • visible | appear // e.g. $("input").shouldBe(visible) (instead of $("input").shouldBe(Condition.visible))
  • present | exist // conditions to wait for element existence in DOM (it can be still hidden)
  • hidden | disappear | not(visible)
  • readonly // e.g. $("input").shouldBe(readonly)
  • name // e.g. $("input").shouldHave(name("fname"))
  • value // e.g. $("input").shouldHave(value("John"))
  • type // e.g. $("#input").shouldHave(type("checkbox"))
  • id // e.g. $("#input").shouldHave(id("myForm"))
  • empty // e.g. $("h2").shouldBe(empty)
  • attribute(name) // e.g. $("#input").shouldHave(attribute("required"))
  • attribute(name, value) // e.g. $("#list li").shouldHave(attribute("class", "active checked"))
  • cssClass(String) // e.g. $("#list li").shouldHave(cssClass("checked"))
  • focused
  • enabled
  • disabled
  • selected
  • matchText(String regex)
  • text(String substring)
  • exactText(String wholeText)
  • textCaseSensitive(String substring)
  • exactTextCaseSensitive(String wholeText)
  • and
  • or
  • not

You can build composite conditions like this:

Condition clickable = and("can be clicked", visible, enabled);
$$(".button").findBy(clickable).click()

Any condition can be negated:

//...
log("Hidden or disabled items: " + $$(".item").filterBy(not(clickable)).size());

You can build a custom condition by extending the com.codeborne.selenide.Condition class, like this:

    public static Condition css(final String propName, final String propValue) {
        return new Condition("css") {
            @Override
            public boolean apply(WebElement element) {
                return propValue.equalsIgnoreCase(element.getCssValue(propName));
            }

            @Override
            public String actualValue(WebElement element) {
                return element.getCssValue(propName);
            }
        };
    }

//...
$("h1").shouldHave(css("font-size", "16px"));

results matching ""

    No results matching ""