【问题标题】:StaleElementException after Selenium updateSelenium 更新后的 StaleElementException
【发布时间】:2017-11-07 15:21:31
【问题描述】:

我在测试中使用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 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


    【解决方案1】:

    有同样的问题。第一次单击工作正常,第二次单击(没有 dom 更改!)抛出异常! 用 clickElement.Click() 替换 action.clikc(clikckingElement).build.perform 有帮助。但这肯定是一个错误!

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

    【讨论】:

    • 我发现我正在使用静态操作,它也会重复所有以前执行的操作。所以现在我在我使用它的每个扩展方法中创建 Actions 实例。这消除了我的一些问题,但不是全部。
    • 每次我打算使用 \click 时都会重新创建一个元素。
    • 不是元素,而是Actions 对象的实例。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-13
    • 1970-01-01
    相关资源
    最近更新 更多