#c# #visual-studio-2010 #coded-ui-tests
#c# #visual-studio-2010 #coded-ui-tests
Вопрос:
Могу ли я найти все ссылки на веб-странице с помощью Coded UI Test Builder, или я должен сделать HTTP-запрос и проанализировать HTML?
Ответ №1:
Вы могли бы сделать что-то вроде этого…
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);
}
}