- 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 handlevar originalTabInstance = myWebDriverInstance.CurrentWindowHandle;// execute some JavaScript to open a new windowmyWebDriverInstance.ExecuteJavaScript("window.open();");// save a reference to our new tab's window handle, this would be the last entry in the WindowHandles collectionvar newTabInstance = myWebDriverInstance.WindowHandles[Driver.Instance.WindowHandles.Count - 1];// switch our WebDriver to the new tab's window handlemyWebDriverInstance.SwitchTo().Window(newTabInstance);// lets navigate to a web site in our new tabmyWebDriverInstance.Navigate().GoToUrl("www.crowbarsolutions.com");// now lets close our new tabmyWebDriverInstance.ExecuteJavaScript("window.close();");// and switch our WebDriver back to the original tab's window handlemyWebDriverInstance.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