-1

I write some automation code in Selenide for practice.

I have following problem: i don't know whats going on, but sometimes on method clickFillExpertsApplication Selenide clicks on localized button, loading of new page is starting, but after 1 sec loading of new page is terminated, page stops on view with the element I wanted to click and program gives me exception (element from next step (on next page) not found). Do You have any experience with 'terminated' clicks?

I tried to avoid it by adding second click in function, but probably this is not the perfect solution it sometimes fails

    fillExpertsApplication.shouldBe(enabled).click();
    Thread.sleep(100);
    if (fillExpertsApplication.isDisplayed()){
       log.info("retry fill experts click");
       fillExpertsApplication.click();
    }

Maybe problem is in my project, maybe I wrote something silly out there, i dont know

moroyoung11
  • 63
  • 1
  • 9

1 Answers1

0

To understand the root of the problem, I need more information. But looking into your code, I understand the reason for failure might be because of your code writing:

Never use Thread.sleep() and if statement with isDisplayed(). Reason: Thread.sleep() - always causes your application to wait n time which is absolutely useless when using Selenide. If you want to wait for something to happen, use Condition function provided by Selenide like: $("some_css_selector").shouldBe(Condition.visible). This will ensure that something should be visible and waits n time configured in your Timeouts.

If statement - Problem with that is: usually, your browser and elements are not loaded upon this statement and you cannot control it with Thread.sleep because if something loads more than your sleep, a test is going to miss your if statement as it will not be visible at the time it was there. The Solution is the same described in the previous section: use selenide conditions $(byText("Submit")).shouldBe(Condition.visible); This will wait till text(for example submit button text) will be visible and will wait for it until a timeout will fail.

imbasheep
  • 92
  • 3
  • 9