我需要while循环的帮助,下面有一个页面代码,我已经这样做了:
<div class="list">
<span class="destination">
<a tabindex="20" href="/flights-to/uk/cheap-flights-to-united-kingdom.html">United Kingdom</a>
</span>
<span class="destination">
<a tabindex="21" href="/flights-to/es/cheap-flights-to-spain.html">Spain</a>
</span>
<span class="destination">
<a tabindex="22" href="/flights-to/us/cheap-flights-to-united-states.html">United States</a>
</span>
<span class="destination">
<span class="destination">
<span class="destination">
<span class="destination">
<span class="destination">
<span class="destination">
<span class="destination">
<a tabindex="29" href="/flights-to/belf/cheap-flights-to-belfast.html">Belfast</a>
</span>
</div>
我必须准备脚本,点击每个链接并检查是否没有例如404错误。
我可以在Selenium IDE中完成,但我不知道我应该如何从C#和Selenium2开始。也许有人有一些提示?
答案 0 :(得分:0)
这样的事情应该有效。
string url = "testpageurl";
IWebdriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl(url);
var links = driver.FindElements(By.TagName("a"));
for(int i=0; i<links.Count; i++ )
{
driver.Navigate().GoToUrl(url);
driver.FindElements(By.TagName("a"))[i].Click();
Assert.IsFalse(driver.FindElement(By.TagName("body")).Text.Contains("404"));
}