Wait for a particular URL in selenium Wait for a particular URL in selenium selenium selenium

Wait for a particular URL in selenium


I'm not sure what language you're using, but in Java you can do something like this:

new WebDriverWait(driver, 20).Until(ExpectedConditions.UrlToBe("my-url"));

To wait until your url has loaded.

If you cannot use the latest selenium version for some reason, you can implement the method yourself:

public static Func<IWebDriver, bool> UrlToBe(string url){    return (driver) => { return driver.Url.ToLowerInvariant().Equals(url.ToLowerInvariant()); };}


They have added more support for expected conditions now. You would have to create a webdriver wait and expect the url to contain a value

WebDriverWait wait = new WebDriverWait(yourDriver, TimeSpan.FromSeconds(5));wait.Until(ExpectedConditions.UrlContains("/url-fragment"));