Search code examples
javaseleniumselenide

Catching shouldHave/shouldBe method in Selenide


I'm writing a test and there's a possibility to not load all fields correctly. I was thinking about using simple try/catch, but when I use

$("select[formcontrolname=\"idenifier\"]").shouldBe(disabled);

I get:

Element should be disabled {input[type="text"]}
Element: '<input class="col-md-8 col-sm-12 col-xs-12 with-tooltip ng-untouched ng-pristine ng-invalid" formcontrolname="identifier" placeholder="e.g. "America" type="text"></input>'
Actual value: enabled

Which is not a standard exception. How can I catch it?


Solution

  • You can catch an AssertionError thrown from any of Selenide's assertions.

    You probably shouldn't though, usually when your assertion is not being met by a certain timeout, you either have a bug or an incorrect assertion.