com.codeborne.selenide.Selenide [src]

The core of the library. Main methods are open, $ и $$:

  • $(String cssSelector) – returns object of the SelenideElement class that represents first element found by CSS selector on the page.
  • $(By) – returns "first SelenideElement" by the locator of the By class.
  • $$(String cssSelector) – returns object of type ElementsCollection that represents collection of all elements found by a CSS selector
  • $$(By) – returns "collection of elements" by the locator of By type.

Usually, when you get a SelenideElement object by the Dollar $ command, you can perform some action on it:

  • $(byText("Sign in")).click();

or even several actions at once:

  • $(byName("password")).setValue("qwerty").pressEnter();

or you can check some condition:

  • $(".welcome-message").shouldHave(text("Welcome, user!")).

"Double Dollar" command ($$) can be useful when a needed element is a one of a same type. For example, instead of:


you can use more readable and verbose alternative:

$$("#search-results a").findBy(text("")).click();

Such "composite locator" has the following advantage. In case of error during locating an element, it will result in more informative message. Since we broke down the locator into smaller parts, the error will show exactly which part caused the fail. And in case of "one long solid locator" we would be able to know that "all locator" did not work, with no any idea about which part really caused the fail.

In addition, if we need to work with different elements of the same collection, we now can "put" a collection to a variable:

ElementsCollection resultLinks = $$("#search-results a");

Now we do not duplicate the "#search-results a" locator in different places. Therefore, if this part changes - we will perform corresponding changes only in one place.

Moreover, now having a separate name for the locator you can use the "autocomplete" feature of your IDE to type resultLinks faster.

Don't be shy to search for more methods inside the Selenide class that can suit your needs. Just type in your IDE Selenide. and choose the needed option among available IDE proposals.

Here are just a few examples:

  • sleep()
  • refresh()
  • title()
  • executeJavaScript(String jsCode, Object... arguments)

results matching ""

    No results matching ""