Skip to content

Instantly share code, notes, and snippets.

@jimevans
Last active May 1, 2020 14:27
Show Gist options
  • Select an option

  • Save jimevans/91249828e7a8fcb79922b12a1a72874d to your computer and use it in GitHub Desktop.

Select an option

Save jimevans/91249828e7a8fcb79922b12a1a72874d to your computer and use it in GitHub Desktop.
// This sample assumes driver is a valid IWebDriver, and that
// elementThatPopsUpNewTab is a valid, already located IWebElement
// that, when clicked, follows a link that will open a new tab.
IList<string> existingHandles = driver.WindowHandles;
elementThatPopsUpNewTab.Click();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
string newTabHandle = wait.Until<string>((d) =>
{
string foundHandle = null;
IList<string> differentHandles = d.WindowHandles.Except(existingHandles).ToList();
if (differentHandles.Count > 0)
{
foundHandle = differentHandles[0];
}
return foundHandle;
});
driver.SwitchTo().Window(newTabHandle);
@MESWEB

MESWEB commented May 1, 2020

Copy link
Copy Markdown

This code give me error: "Timed out after 5 seconds"

@jimevans

jimevans commented May 1, 2020

Copy link
Copy Markdown
Author

@MESWEB Then you'll need to provide some code of your own that uses a real site that is failing for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment