How to get webDriver to wait for page to load (C# Selenium project) : <p>I've started a Selenium project in C#. Trying to wait for page to finish loading up and only afterwards proceed to next action.</p>

<p>My code looks like this:</p>

<pre><code> loginPage.GoToLoginPage();
        loginPage.LoginAs(TestCase.Username, TestCase.Password);
        loginPage.SelectRole(TestCase.Orgunit);
        loginPage.AcceptRole();
</code></pre>

<p>inside loginPage.SelectRole(TestCase.Orgunit):</p>

<pre><code> RoleHierachyLabel = CommonsBasePage.Driver.FindElement(By.XPath("//span[contains(text(), " + role + ")]"));
 RoleHierachyLabel.Click();
 RoleLoginButton.Click();
</code></pre>

<p>I search for element RoleHierachyLabel. I've been trying to use multiple ways to wait for page to load or search for an element property allowing for some timeout:</p>

<pre><code>1. _browserInstance.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
</code></pre>

<hr>

<pre><code>2. public static bool WaitUntilElementIsPresent(RemoteWebDriver driver, By by, int timeout = 5)
    {
        for (var i = 0; i &lt; timeout; i++)
        {
            if (driver.ElementExists(by)) return true;
        }
        return false;
    }
</code></pre>

<p>How would you tackle this obstacle?</p>
