Similar HTML Tag with Coded UI

List all similar Html Tag
To list all “P” tag of a website we need to use the following code –

        public void MyTestInitialize()

        public void CodedUITestMethod1()
            BrowserWindow Browser = new BrowserWindow();
            Browser.SearchProperties[UITestControl.PropertyNames.Name] = "Automation Sample 1:: Tanmay Sarkar";

         HtmlControl AllPtag = new HtmlControl(Browser);
            AllPtag.SearchProperties[HtmlControl.PropertyNames.TagName] = "p";
            UITestControlCollection collection = AllPtag.FindMatchingControls();
            foreach (HtmlControl each in collection)


And the output should contain all the p tag of site –

To get a particular p tag inner text from this collection we can modify our code like –

HtmlControl Sample = new HtmlControl(Browser);
            Sample.SearchProperties[HtmlControl.PropertyNames.TagName] = "p";
            UITestControlCollection col = AllPtag.FindMatchingControls();

And the out put will be –

Related posts:

Leave a Reply

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