用Telerik';的WebAii框架

本文关键字:WebAii 框架 Telerik | 更新日期: 2023-09-27 18:00:19

我需要找到具有特定id的Span内的每个HtmlAnchor

<span id="ctl05_dpIncidentFailures">
<span>1</span> // page 1
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=2">2</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=3">3</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=4">4</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=5">5</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=6">6</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=7">7</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=8">8</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=9">9</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=10">10</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=11">11</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=12">12</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=13">13</a>
</span>

我如何使用WebAii做到这一点?这就是我迄今为止所尝试的:

IList<Element> allbtns = Find.AllByAttributes("href=~pageid"); // not working
var _pagingList = Find.ById<HtmlSpan>("~dpIncidentFailures"); // not working either

用Telerik';的WebAii框架

我已经解决了我的问题:

    [TestMethod]
    public void TestPagingCauseFailure()
    {
        // act
        OpenPage(true);
        // get the hidden fields on this page
        IList<HtmlInputHidden> _hiddenFieldsList = Find.AllByAttributes<HtmlInputHidden>("~hfFailureID");
        IList<HtmlAnchor> _pageIndexes = Find.AllByAttributes<HtmlAnchor>("href=~pageid");
        // there are 12 pages (not including page 1)
        Assert.IsTrue(Equals(12,_pageIndexes.Count));
        // goto last page
        _pageIndexes.Last().Click();
        //get the hidden fields on this page
        IList<HtmlInputHidden> _hiddenFieldsList2 = Find.AllByAttributes<HtmlInputHidden>("~hfFailureID");
        string value1 = _hiddenFieldsList.Last().ID;
        string value2 = _hiddenFieldsList2.Last().ID;
        //compare the two last items in boths lists
        Assert.IsFalse(Equals(value1, value2));
    }