Docs

Poor software doesn't have documentation. Brilliant software doesn't need it.

Selenide is simple enough that you won't need tons of docs. The whole API is three things: open a page, find an element, act or check. Here is the reference for everything else.

Three simple things

  1. Open the page: open(url)
  2. Find an element and act on it: $(selector).click()
  3. Check a condition: $(selector).shouldHave(text("..."))
open("/login");
$("#submit").click();
$(".message").shouldHave(text("Hello"));

That’s it. Everything below is detail.

Use the power of your IDE

The Selenide API is just a few classes. We suggest you stop reading, open your IDE and start typing.

Type $(selector). and your IDE will suggest everything you can do with the element:

Selenide API: just start typing in your IDE

Your IDE beats any documentation, and so does your AI assistant: Selenide’s API is small and stable, so models write it well.

Selenide API reference

The complete reference is in the Selenide javadoc. For a guided tour of how Selenide works inside, see Selenide on DeepWiki. These are the classes you’ll use most of the time.

com.codeborne.selenide.Selenide

source · javadoc

The core of the library. The main methods are open, $ and $$. Import them statically for readability: import static com.codeborne.selenide.Selenide.*.

  • open(String url) opens the browser (if it isn’t open yet) and loads the URL.
  • $(String cssSelector) returns a SelenideElement: the first element on the page matching the CSS selector.
  • $(By) does the same for any By locator.
  • $$(String cssSelector) returns an ElementsCollection: all elements matching the CSS selector.
  • $$(By) does the same for any By locator.

In Kotlin, where $ is awkward, use the aliases element() and elements().

When you get a SelenideElement with $, you can perform an action on it:

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

or several actions at once:

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

or check a condition:

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

The double dollar $$ is handy when the element you need is one of many similar ones. Instead of

$(byXpath("//*[@id='search-results']//a[contains(text(),'selenide.org')]")).click();

write the more readable

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

Most operations on elements found by $ and $$ wait automatically, as long as the context needs. So in most cases you don’t need to think about waiting at all, even on highly dynamic pages.

Don’t be shy to look for more methods in the Selenide class: type Selenide. in your IDE and browse the suggestions. A few examples: sleep(), refresh(), title(), executeJavaScript(String jsCode, Object… arguments).

com.codeborne.selenide.SelenideElement

source · javadoc

SelenideElement represents an element on the page. You usually get one from $. It’s lazy: Selenide looks the element up only when you use it, and looks it up again if the page has changed.

Finding inner elements

  • find(String cssSelector) / $(String cssSelector)
  • find(By) / $(By)
  • findAll(String cssSelector) / $$(String cssSelector)
  • findAll(By) / $$(By)

$ and $$ are short aliases for find and findAll. Use them to build a locator chain step by step:

$("#header").find("#menu").findAll(".item");

Checks (assertions)

  • should(Condition) / shouldBe(Condition) / shouldHave(Condition)
  • shouldNot(Condition) / shouldNotBe(Condition) / shouldNotHave(Condition)

Pick the alias that makes the line read like an English sentence:

$("input").should(exist);
$("input").shouldBe(visible);
$("input").shouldHave(exactText("Some text"));

Checks are Selenide’s explicit waits. They wait until the condition (visible, enabled, text("some text")) is met or the timeout runs out. The timeout is Configuration.timeout, 4000 ms by default. You can use a check before an action to wait for the right state: $("#submit").shouldBe(enabled).click();

You can also set the timeout for a single check:

$("input").shouldBe(visible, Duration.ofSeconds(30));

Actions

  • click(), doubleClick(), contextClick(), hover()
  • setValue(String) / val(String), append(String), clear()
  • pressEnter(), pressEscape(), pressTab(), press(Keys...)
  • selectOption(String), selectOptionByValue(String), selectRadio(String value), setSelected(boolean)
  • dragAndDrop(to("#target")), scrollTo(), scrollIntoView(...)
  • …

Most actions return the same SelenideElement, so you can chain them: $("#edit").setValue("text").pressEnter();

Getting state and attributes

  • getValue() / val()
  • attr(String), data(String)
  • text(): the visible text on the page
  • innerText(): the text of the element in the DOM
  • getSelectedOption(), getSelectedOptionText(), getSelectedOptionValue()
  • isDisplayed(): false if the element is hidden or doesn’t exist in the DOM, otherwise true
  • exists(): true if the element exists in the DOM, otherwise false

Other useful methods

  • uploadFromClasspath(String fileName), uploadFile(File...)
  • download(): downloads a file and returns it
  • screenshot(): takes a screenshot of just this element
  • toWebElement(): gives you the raw Selenium WebElement

com.codeborne.selenide.Condition

source · javadoc

Conditions are used in should / shouldNot checks. Import them statically to keep the code readable:

ConditionExample
visible / appear$("input").shouldBe(visible)
existthe element exists in the DOM, possibly hidden
hidden / disappear$(".spinner").should(disappear)
enabled / disabled$("#submit").shouldBe(enabled)
interactable, clickable, editable$("#name").shouldBe(editable)
checked, selected, focused, readonly, empty$("h2").shouldBe(empty)
text(String)substring: $("h1").shouldHave(text("Hello"))
exactText(String)the whole text
textCaseSensitive(String), exactTextCaseSensitive(String)
matchText(String regex)$("#id").shouldHave(matchText("\\d+"))
value(String), name(String), id(String), type(String)$("input").shouldHave(value("John"))
attribute(name), attribute(name, value)$("#input").shouldHave(attribute("required"))
cssClass(String)$("#list li").shouldHave(cssClass("checked"))

com.codeborne.selenide.Selectors

source · javadoc

By selectors that standard Selenium WebDriver doesn’t have: find elements by text, attributes, labels or inside shadow DOM.

  • byText finds an element by its exact text, withText by a substring.
  • byLabel finds an input by the text of its label.
  • byPlaceholder, byTitle, byValue, byAltText find elements by those attributes.
  • byTestId finds an element by its data-test-id attribute.
  • by(attributeName, attributeValue) finds an element by any attribute.
  • shadowCss(selector, shadowHost) finds an element inside shadow DOM.
  • byXpath, byId, byName, byClassName… for everything else.
$(byText("Login")).shouldBe(visible);
$(byLabel("Email")).setValue("john@example.com");
$(By.xpath("//div[text()='Login']")).shouldBe(visible);  // any org.openqa.selenium.By works
$(byXpath("//div[text()='Login']")).shouldBe(visible);   // or its alternative from Selectors

com.codeborne.selenide.ElementsCollection

source · javadoc

A collection of all elements matching a locator. You usually get one from $$.

Checks

  • shouldBe, e.g. $$(".errors").shouldBe(empty)
  • shouldHave, e.g. $$("#mytable tbody tr").shouldHave(size(2))

Collection checks wait too, until the condition (size(2), empty, texts("a", "b", "c")) is met or Configuration.timeout runs out.

Getting state

  • size(), isEmpty()
  • texts(): the visible texts of all elements, e.g. ["a", "", "c"] for <li>a</li><li hidden>b</li><li>c</li>

Picking elements

  • filterBy(Condition) returns only the elements that match the condition, e.g. $$("#multirowTable tr").filterBy(text("Norris"))
  • excludeWith(Condition) does the opposite, e.g. $$("#multirowTable tr").excludeWith(text("Chuck"))
  • get(int) returns the n-th element as a SelenideElement
  • first(), last()
  • findBy(Condition) returns the first element that matches the condition

com.codeborne.selenide.CollectionCondition

source · javadoc

Conditions for ElementsCollection checks. Import them statically, too.

  • empty, e.g. $$("#list li").shouldBe(empty)
  • size(int), e.g. $$("#list li").shouldHave(size(10))
  • sizeGreaterThan(int), sizeGreaterThanOrEqual(int), sizeLessThan(int), sizeLessThanOrEqual(int), sizeNotEqual(int)
  • texts(String...): substrings, exactTexts(String...): whole texts, textsInAnyOrder(String...)
  • itemWithText(String), allMatch(...), anyMatch(...), noneMatch(...), attributes(...)

com.codeborne.selenide.WebDriverRunner

source · javadoc

Browser management methods:

  • isChrome(), isFirefox(), isHeadless()
  • url() returns the current URL
  • source() returns the HTML source of the current page
  • getWebDriver() returns the WebDriver instance (created by Selenide or set by you), so you always have the raw Selenium API at hand
  • setWebDriver(WebDriver) tells Selenide to use a driver you created yourself. From then on, closing it is your job (e.g. getWebDriver().quit()).

com.codeborne.selenide.Configuration

source · javadoc

Settings for your Selenide tests, for example:

  • timeout: how long checks and actions wait, in milliseconds. 4000 by default; change it with e.g. Configuration.timeout = 6000;
  • browser: "chrome", "firefox", "edge", "safari"
  • headless
  • baseUrl
  • remote: the URL of a Selenium Grid or a cloud provider
  • reportsFolder
  • …

Every setting can also be passed as a system property, which is handy on CI: -Dselenide.baseUrl=https://staging-server.com/start. Or put them in src/test/resources/selenide.properties. See the FAQ for details.

Didn't find the answer?

Ask the community, we answer fast: GitHub Discussions · Telegram · Report an issue