使用 Telerik 的 WebAii 框架测试分页

发布于 2024-11-16 22:16:37 字数 1905 浏览 6 评论 0原文

我需要找到具有特定 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

I need to find every HtmlAnchor inside a Span with a specific id:

<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>

How could I do this using WebAii? This is what I have tried up to now:

IList<Element> allbtns = Find.AllByAttributes("href=~pageid"); // not working

var _pagingList = Find.ById<HtmlSpan>("~dpIncidentFailures"); // not working either

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴骨ら 2024-11-23 22:16:37

我已经解决了我的问题:

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

    }

I have solved my issue:

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

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文