1 Ağustos 2017 Salı

selenium tab commands


  • Create a new tab
  • Switch to it
  • Do something in the new tab
  • Close the new tab
  • Switch back to our original tab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// save a reference to our original tab's window handle
var originalTabInstance = myWebDriverInstance.CurrentWindowHandle;
// execute some JavaScript to open a new window
myWebDriverInstance.ExecuteJavaScript("window.open();");
// save a reference to our new tab's window handle, this would be the last entry in the WindowHandles collection
var newTabInstance = myWebDriverInstance.WindowHandles[Driver.Instance.WindowHandles.Count - 1];
// switch our WebDriver to the new tab's window handle
myWebDriverInstance.SwitchTo().Window(newTabInstance);
// lets navigate to a web site in our new tab
myWebDriverInstance.Navigate().GoToUrl("www.crowbarsolutions.com");
// now lets close our new tab
myWebDriverInstance.ExecuteJavaScript("window.close();");
// and switch our WebDriver back to the original tab's window handle
myWebDriverInstance.SwitchTo().Window(originalTabInstance);
// and have our WebDriver focus on the main document in the page to send commands to
myWebDriverInstance.SwitchTo().DefaultContent();

Hiç yorum yok:

Yorum Gönder