如何使用C#使用Selenium WebDriver知道URL?

时间:2018-11-19 10:12:55

标签: c# selenium selenium-webdriver

在我的应用程序中,我存储一个URL列表,仅存储具有现有URL(即找不到任何404或Page或URL损坏)的产品。

我想在我的页面中查看,然后导航到该页面。现在,我需要获取使用Selenium和C#中的WebDriver检查给定URL是否存在的代码。

1 个答案:

答案 0 :(得分:0)

string urlFraction = "/myfolder/some.html";
double seconds = 10;
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(seconds));
bool wellTheAddressBarChanged = wait.Until(ExpectedConditions.UrlContains(urlFraction));

// TODO: Give IE11 special treatment here.
bool thePageActuallyLoaded = wait.Until(d => ((IJavaScriptExecutor)d).ExecuteScript("return document.readyState").Equals("complete"));