"The only source of knowledge is experience" - Albert Einstein-

How to find controls in new Tabs of your browser with CodedUI

One question I got recently is if it is possible to find controls on secondary tabs that are created by an application when using CodedUI. the answer is yes and I thought it would be handy to write up how to make this happen.

For purpose of the sample I create a simple ASP.NET MVC website and changed the default page to have a link button that creates a new page in a second tab.

The page looks as follows:


When I click the button, then a new tab is opened and that will show the following page:


As you can see I have done a lot of work to make the page look pretty Smile but that was not the purpose, it is to get the point across how to find the Html on the second tab.

The way you do this is as follows:

  • You first start your test, by using the BrowserWindow class and call Launch to start the browser.
  • Next you find the HtmlHyperlink to execute the click on the button.
  • Now you have the second tab show up, and to locate that tab, you can use the BrowserWindow class again. this time you use the static method Locate and pass it in the title of the document you try to find. In my case that new tab has the Title “New Tab”
  • This locate method, returns a new BrowserWindow object that I can use in my subsequent searches for controls. So to find the text on the page I can create an HtmlDiv object, pass it in the SearchProperty Id with the value of “itemToFind” and get the InnerText value of the control to assert in my test.

The code looks as follows:

And that is it, this is the way to create tests that can work with with multiple tabs in your browser

I have the sample project up here for you to download and test yourself.

If you want to learn more about CodedUI and how this technology works, you might want to check out my course at Pluralsight on CodedUI. You can find it here and even watch it for free if you don’t have an account, by applying for a Trial.

hope this helps,


  1. Garland Kuntz

    I have a web table where the first row (headers) have two controls in each cell. One control controls sorting and the other control opens a popup. The first control is easy to access and click. The second control has me stumped. I can access it using TagInstance but that is not best way.
    Can you demonstrate how to access two controls in one cell of a web table?

    • Marcel

      can you provide me with a small snippet of the HTML of the table, so I can provide a simple sample?
      Has the second control any way to uniquely identify it, or is it always just the 2nth control in the cell?

      • Garland Kuntz

        Marcel, thanks very much for replying. The second control has no unique identifier except for the TagInstance which is not ideal. I was able to figure how to use getChildren and FindMatchingControls to successfully click on the second control. I am hoping the developers will have unique IDs for all future controls. We enjoyed your presentation at KPMG and learned lots.


  2. Garland Kuntz

    I should have added that I am using hand code and no UIMap.

  3. Jahan

    Hi Marcel,

    I finished watching your Pluralsight course on CodedUI Web. I am trying to build the whole folder/file structure for a website testing project in VS2017. Any suggestion on Solution/Project/Folder/files structure? and the best practice?


    • Marcel

      not really. If you structure the folders according to logical functional areas in your application then you are in a good shape

  4. Shashank

    Hi Marcel,
    I am using VS2013 with Firefox(using selenium components) and facing problem in switching to the new browser window as the Locate method is not working, any suggestion.

  5. Siva

    Hi Marcel,

    I am working for a project in this click on button it is opening the new window with different parameters each time. Parameters are changing for each request. I want to pick the opened window and i have to insert the value into textbox and this is available in new window.

    *** This is not new tab NEW WINDOW only*****

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2020 Fluent Bytes

Theme by Anders NorenUp ↑