【发布时间】:2015-03-29 15:12:16
【问题描述】:
我正在尝试自动测试网站上的所有链接。 但问题是我的 foreach 循环在第一次点击后停止。
当我 Console.log 属性时,它会写出所有链接,但在单击时不会这样做:)
这会注销所有链接。
[FindsBy(How = How.TagName, Using = "a")]
public IWebElement hrefClick { get; set; }
public void TestT2Links()
{
foreach (IWebElement item in PropertiesCollection.driver.FindElements(By.TagName("a")))
{
Console.WriteLine(item.GetAttribute("href"));
}
}
但是当我尝试 Click() 函数时,它只会点击第一个链接。
[FindsBy(How = How.TagName, Using = "a")]
public IWebElement hrefClick { get; set; }
public void TestT2Links()
{
foreach (IWebElement item in PropertiesCollection.driver.FindElements(By.TagName("a")))
{
hrefClick.Click();
Console.WriteLine(item.GetAttribute("href"));
}
}
我还尝试了每次点击后返回导航的返回方法,但也无用且错误:(
PropertiesCollection.driver.Navigate().Back();
有什么建议吗?
【问题讨论】: