How to find all links on a web page using Coded UI Test?

Can I find all links on a web page using Coded UI Test Builder, or do I need to make an HTTP request and parse the HTML?

+4
source share
1 answer

You can do something like this ...

BrowserWindow bw = BrowserWindow.Launch(new Uri("http://www.google.com")); bw.WaitForControlReady(); UITestControl document = bw.CurrentDocumentWindow; HtmlControl control = new HtmlControl(document); control.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, "HtmlHyperlink"); UITestControlCollection controlcollection = control.FindMatchingControls(); List<string> names = new List<string>(); foreach (UITestControl x in controlcollection) { if (x is HtmlHyperlink) { HtmlHyperlink s = (HtmlHyperlink)x; names.Add(s.Href); } } 
+8
source

All Articles