Issue
When using wait.Until()
in a try / catch block, if the element isn't there it throws NoSuchElementException exception. However, when I try to catch the exception, I still get the error.
try
{
wait.Until(el => el.FindElement(By.Id("courseTestItem")));
driver.Close();
driver.SwitchTo().Window(driver.WindowHandles.Last());
Console.WriteLine("Skipped: " + courses[0].Item1.Text + " (Has test)");
}
catch (OpenQA.Selenium.NoSuchElementException) { }
I even tried just using a catch (Exception e) { }
and that still didn't catch the error.
Solution
Instead of using a try / catch use:
if (wait.Until(el => el.FindElements(By.Id("filterText"))).Count > 0) { }
else if (wait.Until(el => el.FindElements(By.Id("sp-search-results-search"))).Count > 0) { }
else System.Threading.Thread.Sleep(5000);
This checks to see if more than 0 elements matching the criteria is found, meaning that the element was found.
Thanks to u/Simmo7 on Reddit for the help.
Answered By - ZombieZombi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.