如何使用编码的 UI 测试查找网页中的所有链接

本文关键字:链接 网页 测试 何使用 编码 UI 查找 | 更新日期: 2023-09-27 17:56:03

我可以使用编码的 UI 测试生成器在网页中找到所有链接,还是必须发出 HTTP 请求并解析 HTML?

如何使用编码的 UI 测试查找网页中的所有链接

你可以做这样的事情...

        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);
            }
        }