Switch Comands



What is switch command?
Webdriver library contains a set of classes and methods that help us to communicate with the web browser. In most of testing scenarios we find element on the website and then click it in case of buttons or fill the text in case of text boxes. Often, it’s enough when you begin to automate your tests in the web browser.
However, at some point you may get stuck discovering that you’re not able to find the element on the page. The first thing that you should ask yourself is: Maybe my application opened a new popup window and the element that I’m trying to find is placed in this new window? If your answer is “YES” – remember one thing:
The new popup window (or new tab) shows another HTML page which opens in a new context, so you should switch context to the new window first and then you can communicate with the new window. This is exactly what switch command comes into play.
Selenium WebDriver in C#: Switch To new window or tab
//switch to new window.
driver.SwitchTo().Window(driver.WindowHandles.Last());

//if you want to switch back to your first window
driver.SwitchTo().Window(driver.WindowHandles.First());

0 comments:

Post a Comment

Copyright © Learn software testing - Blogger Theme by BloggerThemes & newwpthemes - Sponsored by Internet Entrepreneur