There are three ways to solve this, you can use any of these or combine them:
1.) Immediately after creating the Selenium web driver instance, set implicit wait : driver.manage().timeouts().implicitlyWait(). This will tell the driver, the amount of time it should wait when finding an element if it is not immediately present after the page is loaded.
Sample code in C# is shown below:
new WebDriverWait(driver, MyDefaultTimeout).Until(
new WebDriverWait(firefoxDriver, pageLoadTimeout).until(
3.) After performing step 2, check if the URL matches the pattern you expect.
To know more about Selenium, you can go through the Selenium course page by Intellipaat.