【发布时间】:2017-11-07 15:21:31
【问题描述】:
我在测试中使用Selenium.WebDriver 和Selenium.Support 3.0.1,但在更新到更高版本后我的代码会抛出错误。
失败代码:
// Element locating
// [FindsBy(How = How.ClassName, Using = "dot")]
// private IList<IWebElement> gameDots { get; set; }
for (int i = 0; i < levelIndicators.Count; i++)
{
Browser.Action.ClickAndHold(gameDots[0]);
foreach (IWebElement gameDot in gameDots)
{
Browser.Action.MoveToElement(gameDot);
}
Browser.Action.MoveToElement(gameDots[0])
.Build()
.Perform();
}
浏览器类:
public static Actions Action { get; set; }
public static IWebDriver Driver { get; set; }
static Browser()
{
Action = new Actions(Driver);
}
更新到任何较新版本的 Selenium 后,我将使用 Perform() 方法获得 StaleElementReferenceException。降级到 3.0.1 后,它又可以工作了。
OpenQA.Selenium.StaleElementReferenceException : stale element reference: element is not attach to the page document (Session info: chrome=58.0.3029.110) (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 10.0. 15063 x86_64)
如果我尝试与gameDot[0] 元素交互而不做任何Actions 一切都会按预期工作。
【问题讨论】:
标签: c# selenium selenium-webdriver webdriver