Wait Until Element Is Hidden upon Page Initialization

How to wait for an element to become hidden upon page initialization.

Given

There is a page with loading indicator displayed while the page is loading. During the navigation to this page the test has to wait until the loading indicator element is hidden and only then start interaction with the page.

<div class="loading-indicator">
    <span class="glyphicon glyphicon-repeat"></span>
    Please wait...
</div>
Please wait...

Implementation

You can choose one of the solutions below.

Using WaitForElement Trigger

using Atata;

namespace SampleApp.UITests
{
    using _ = SomePage;

    [WaitForElement(WaitBy.Class, "loading-indicator", WaitUntil.MissingOrHidden, TriggerEvents.Init)]
    public class SomePage : Page<_>
    {
    }
}

Using WaitFor Trigger

using Atata;

namespace SampleApp.UITests
{
    using _ = SomePage;

    public class SomePage : Page<_>
    {
        [FindByClass]
        [WaitFor(Until.MissingOrHidden)] // By default executes on TriggerEvents.Init.
        public Control<_> LoadingIndicator { get; private set; }
    }
}

Test

Waiting until the element is hidden/missing will be performed upon SomePage page initialization.

Go.To<SomePage>();

Remarks

In order to avoid a duplication of trigger declaration in different page objects, it is possible to extract a trigger definition to the custom trigger class. See Custom Trigger: Wait for Loading Indicator example.