Skip to content

Commit

Permalink
Prevent "Sequence contains no elements" in browser tests (#1261)
Browse files Browse the repository at this point in the history
Capture the collection between the check of elements and LINQ action on it.
  • Loading branch information
ilonatommy authored Sep 6, 2024
1 parent ab05656 commit 8e7ee2e
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ protected override async Task<ExitCode> InvokeInternal(ILogger logger)
driver.Navigate().GoToUrl("about:config");
driver.Navigate().GoToUrl("about:blank");
driver.Close(); //Close Tab
driver.SwitchTo().Window(driver.WindowHandles.Last());

// this is not redundant, it prevents "System.InvalidOperationException: Sequence contains no elements"
var windowHandles = driver.WindowHandles.ToList();
if (windowHandles.Any())
{
driver.SwitchTo().Window(windowHandles.Last());
}
}
if (driverService.IsRunning)
{
Expand Down

0 comments on commit 8e7ee2e

Please sign in to comment.