建议我尝试使用“ 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();
            }
        }
    }

最佳答案

如果找到该值,您应该添加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;
        }
    }
}

10-04 18:51