Sunday, March 27, 2016

Selenium WebDriver in C#: Switch To new window or tab

There are many instances when you click on a link and it opens a new window or tab. Selenim WebDriver provides a way to switch to that new window using SwitchTo() method.
See the code below
IWebDriver driver = new new FirefoxDriver();

//perform some action to open a new window. Like clicking a link.

//switch to new window.

//if you want to switch back to your first window
I hope this little code snippet will help you in your future automation :)


  1. It worked for me. I love it man!

  2. what if we want to handle OS window without using autoIT ?

  3. Hello, It is not working for my workflow, Please help me for below workflow

    1.Open URL, let say
    2. open second window say and switch to this window using above code and it will work as exptected
    3. click download button which is exist in page, it will file download window dialog popup, now I used AUTOIT and able to download by click save button of download
    3 . Open new window and able to switch that new window
    4 closed newly created window and try to switch to 2nd window which had window popup earlier for download, I always get exception of timeout, yes I can increase but it still will not work.

    Can you please help

  4. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.selenium training in bangalore

  5. It's so nice of you to share this snippet here! I'd tried to make out some by myself, but I'm sort of not so good with programming scripts, so my one has just crashed my laptop to death :D So, I did fresh reinstall of windows, there were some issues with dynamic libraries right away, but I've fixed them in easy fashion with using this tool to troubleshoot all the errors like msvcr100.dll missing so my laptop is alive and kicking for now. Anyway, let's check this one snippet of yours

  6. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command.
    software testing course in chennai

  7. Thanks for the useful information of software testing courses, give more updates on software testing development, First time I visit your blog really nice, I bookmark your blog here after a daily visit. Learn software testing course in Chennai

  8. Hi,Nice blog.Thank you so much for sharing this.If you are looking for an used car please visit us

  9. Nice post.Thank you so much for sharing.Yiioverflow is a web development company.We have well expert team in Angular JS, Ionic, Yii Framework, Node JS, Laravel, PHP, MySQL, and WordPress.If you want a developer visit..

  10. Thanks for one marvelous posting! I enjoyed reading it; you are a great author. I will make sure to bookmark your blog and may come back someday. I want to encourage that you continue your great posts, have a nice weekend!
    Online training in USA

  11. Thanks for providing the information . The articles in your blog helped me a lot for improving the knowledge on the subject. Also check my small collection on this at selenium Online Course blog

  12. This concept is a good way to enhance the knowledge.thanks for sharing. please keep it up selenium Online Training Hyderabad

  13. Thank you for sharing a bunch of this quality contents, I have bookmarked your blog. Please also explore advice from my site. I will be back for more quality contents.

  14. Thanks you for sharing the article. The data that you provided in the blog is infromative and effectve. Through you blog I gained so much knowledge.

    Selenium Automation Testing