c# - Selenium 更新后出现 StaleElementException

标签 c# selenium selenium-webdriver webdriver

我在测试中使用 Selenium.WebDriverSelenium.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 attached 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,一切都按预期工作。

最佳答案

遇到同样的问题。第一次点击工作正常,第二次点击(没有 dom 变化!)抛出异常! 将 action.clikc(clikckingElement).build.perform 替换为 clickingElement.Click() 有帮助。但这肯定是一个错误!

crhome v. 59 一切正常,但 selenium 3.0.1 而不是最新的 3.4

关于c# - Selenium 更新后出现 StaleElementException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44392879/

相关文章:

c# - 如何识别域模型中的聚合根?

javascript - 在 C# 中使用身份验证 token 获取用户详细信息

spring - Selenium 测试 : How to bypass okta in selenium

java - 如何使用 Selenium WebDriver 捕获弹出窗口的屏幕?

java - 如何从 Selenium 中的跨度类中获取文本

c# - 将 WebJobs 与 Azure 服务总线和 session 一起使用

c# - Xml反序列化为对象,反射为类型

javascript - 如何使用 R 从国家文件馆 (archives.gov) 中抓取目录系列中的所有文件

javascript - 如何从 Protractor 网络驱动程序获取文本字段值

selenium-webdriver - 获取文本的最佳方式是什么? getText() 不返回 google.co.in 中的链接文本