【问题标题】:Element not found in the cache - perhaps the page has changed since it was looked up c#在缓存中找不到元素 - 页面可能在查找后已更改 c#
【发布时间】:2015-10-15 11:06:49
【问题描述】:

有人建议我尝试使用“StaleElementReferenceException”来处理这个问题,但我不确定如何合并它。如果有人可以提供一些提示,将不胜感激。谢谢你

    [Then(@"I select the following list item '(.*)' from my search")]
    public static void PreSelectedListOptions(string value)
    {
        var suggestedList = Driver.Instance.FindElements(By.CssSelector(".list-reset li"));
        foreach (IWebElement suggestion in suggestedList)
        {
            if (value.Equals(suggestion.Text))
            {
                suggestion.Click();
            }
        }
    }

【问题讨论】:

    标签: c# .net selenium selenium-webdriver


    【解决方案1】:

    您应该添加break;,如果找到该值并单击它,然后它会更改dom,这会导致下一次迭代出现问题。

    [Then(@"I select the following list item '(.*)' from my search")]
    public static void PreSelectedListOptions(string value)
    {
        var suggestedList = Driver.Instance.FindElements(By.CssSelector(".list-reset li"));
        foreach (IWebElement suggestion in suggestedList)
        {
            if (value.Equals(suggestion.Text))
            {
                suggestion.Click();
                break;
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-16
      • 1970-01-01
      相关资源
      最近更新 更多