Reputation: 171
I was advised to try to use 'StaleElementReferenceException' to handle this, but am not sure how to incorporate it. If someone could provide some hints that would be much appreciated. Thank you
[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();
}
}
}
Upvotes: 1
Views: 643
Reputation: 7411
You should add break;
if the value is found it clicks and then it changes the dom
which cause a problem for the next iteration.
[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;
}
}
}
Upvotes: 3