Selenide: Implicite wait

Created on 26 Jan 2017  Â·  5Comments  Â·  Source: selenide/selenide

Does$("") method wait implicite for the element to appear? I guess it does but wanna be sure.
I think should is overengineering in this case right?
$("select[name='swimlanes']").should(Condition.exist).exists();
Sorry for the noob questions.

question

Most helpful comment

@apreg Please don't call exists() and return boolean. It's just nonsense.
Look, we have 2 options:

  1. The element exists. In this case $("...").should(exist).exists(); always returns true.
  2. The element doesn't exist. In this case `$("...").should(exist) throws an exception.

So, your method will never return false. And this is good. You test will either work or fail. Green or red. That's enough.

If you want to use custom error message in case of test failure, you can do it like this:
$("#lastLogin").should(exist.because("Last login should be shown for security reasons"));

All 5 comments

$(„“) does not do any search at all! It just defines locator of element.

but .should* all wait Configuration.timeout ms (it is not the same technology as in implicity Selenium-Waits, though.It is better one! But in general it works like implicit wait, yes.

$(„…“).should(Condition.exist); // no .exists() at the end

Better to static import Condition.*, then you have

$(element).should(exist), $(element).shouldBe(visible), $(element).shouldHave(text(„Ahoi“)) etc.

with nice readability.

Am 26.01.2017 um 11:24 schrieb apreg notifications@github.com:

Does$("") method wait implicite for the element to appear? I guess it does but wanna be sure.
I think should is overengineering in this case right?
$("select[name='swimlanes']").should(Condition.exist).exists();
Sorry for the noob questions.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub https://github.com/codeborne/selenide/issues/460, or mute the thread https://github.com/notifications/unsubscribe-auth/AGQ4YErri9hUD59aOIJ-KUPkeRCpDIMeks5rWHRTgaJpZM4LufBj.

``` /**

  • Find the first element matching given CSS selector
  • @param seleniumSelector any Selenium selector like By.id(), By.name() etc.
  • @return SelenideElement
    */
    public static SelenideElement $(By seleniumSelector) {
    return getElement(seleniumSelector);
    }
    ```

I'm confused.
The problem for me with your proposed solution is that I need to give back a boolean but shouldgives back the element itself. So my final goal is to check whether an element is present with a little waiting.

Thank you it is indeed inconsistency in the docs! But it doesn’t search, believe me.
We’ll change this javadocs for better with new version!

Why do you need to get boolean back? Don’t you want to check if element is there?

use element.shouldBe(visible) for the most cases.
If you really want to wait more than standard for your apps (4-5 secs is typical for the most apps), you can do with

element.waitUntil(visible, 30000); // it is the same as shouldBe, but waits up to 30 seconds

Am 26.01.2017 um 11:36 schrieb apreg notifications@github.com:

` /**

Find the first element matching given CSS selector
@param https://github.com/param seleniumSelector any Selenium selector like By.id(), By.name() etc.
@return https://github.com/return SelenideElement
*/
public static SelenideElement $(By seleniumSelector) {
return getElement(seleniumSelector);
}`
I'm confused.
The problem for me with your proposed solution is that I need to give back a boolean but should gives back the element itself. So my final goal is to check whether an element is present with a little waiting.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/codeborne/selenide/issues/460#issuecomment-275357383, or mute the thread https://github.com/notifications/unsubscribe-auth/AGQ4YAFMwCprJYow_9s34Zc373GPmWKrks5rWHdDgaJpZM4LufBj.

I believe you ;)

Defining SelenideElement doesn’t trigger the search in DOM yet, so you can save the locators in variables for later use at any place. With a SelenideElement instance, you can either do action with it (click, setValue etc.) or check a condition: shouldHave(text("abc")). Both will trigger the search of the elements in DOM.

Why do you need to get boolean back? Don’t you want to check if element is there?

In my pageobject there are helper methods which give back boolean for what I can assert and give custom error message in the test spec class.

So If I get it correctly if I want to wait for an element I should use should or waitUntil or maybe action like click.
I know I have other options too but these are the most prefered ones. To check whether the title is correct I use this method:
Wait().until(ExpectedConditions.titleContains("New View"));
To check page source I use this:

Wait().until(new Function<WebDriver, Boolean>() {
            @Nullable
            @Override
            public Boolean apply(@Nullable WebDriver input) {
                return source().contains(textToContain);
            }
        });

@apreg Please don't call exists() and return boolean. It's just nonsense.
Look, we have 2 options:

  1. The element exists. In this case $("...").should(exist).exists(); always returns true.
  2. The element doesn't exist. In this case `$("...").should(exist) throws an exception.

So, your method will never return false. And this is good. You test will either work or fail. Green or red. That's enough.

If you want to use custom error message in case of test failure, you can do it like this:
$("#lastLogin").should(exist.because("Last login should be shown for security reasons"));

Was this page helpful?
0 / 5 - 0 ratings