我被建议尝试使用' 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();
}
}
}
答案 0 :(得分:3)
如果找到值,则应添加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;
}
}
}