WebAii HtmlControl.Click() 单击了错误的控件

发布于 2024-09-07 11:20:37 字数 1480 浏览 6 评论 0原文

我已经使用过很多次 WebAii 测试框架的免费版本(Art Of Test 在被 Telerik 收购之前发布的版本),所以我知道它基本上可以工作。所以我现在遇到的问题对我来说完全令人困惑。

我正在尝试在现有网站中测试导航,并浏览一系列页面。我进入的页面有(除其他外)两个按钮。一个是“后退”按钮,它是一个按钮类型的输入元素,带有一个 onclick 处理程序,该处理程序调用一个 javascript 函数,该函数只调用history.back()。另一个是提交按钮。

WebAii 找到提交按钮没有问题。但是,当我告诉它单击它时,从所有迹象来看,它都是单击后退按钮。

这是该网站的相关 HTML:

<div align="right"> 
    <table border="0" width="200" cellpadding="8" style="border-collapse: collapse" bordercolor="#E0DFE3"> 
        <tr> 
            <td> 
                <input type="button" value="<- Back" name="B2" onclick="cancelChange()" > 
            </td> 
            <td> 
                <input type="submit" value="Maint Details ->" name="lnkSubmit"> 
            </td> 
        </tr> 
    </table> 
</div> 

这是测试代码:

        HtmlInputSubmit maintDetailsButton = Find.ByAttributes<HtmlInputSubmit>("value=Maint Details ->"); 
        maintDetailsButton.Click(); 

        Assert.IsTrue(ActiveBrowser.Url.Contains(expectedPage), "URL {0} does not contain expected page {1}", ActiveBrowser.Url, expectedPage); 

当我手动单击它时,操作顺序工作得很好,所以我看不到任何证据表明这是该网站的问题。我已经看到大量证据表明,实际上是单击“后退”按钮而不是“维护详细信息”按钮。 (Fiddler 显示发送点击请求时没有发出任何请求 - 与执行 History.back() 一致,因为浏览器只是从缓存中重新显示。当我点击时,它实际上会转到上一页。最后,如果我从后退按钮中删除“onclick”属性,以便单击该按钮不执行任何操作,那么在执行测试代码时,该站点不会执行任何操作 - 只是停留在当前页面上。)

我完全感到困惑。谁能给我提示吗?

I've used the free edition of the WebAii test framework [the one released by Art Of Test before they were acquired by Telerik] quite a bit, so I know it basically works. So the problem I'm having now is completely baffling to me.

I'm trying to test navigation in an existing site, and going through a sequence of pages. I get to a page that has (among other things) two buttons. One is a "back" button that is an input element of type button with an onclick handler that calls a javascript function that just calls history.back(). The other is a submit button.

WebAii has no problem finding the submit button. But when I tell it to click it, it is, to all appearances, clicking the back button.

Here's the relevant HTML from the site:

<div align="right"> 
    <table border="0" width="200" cellpadding="8" style="border-collapse: collapse" bordercolor="#E0DFE3"> 
        <tr> 
            <td> 
                <input type="button" value="<- Back" name="B2" onclick="cancelChange()" > 
            </td> 
            <td> 
                <input type="submit" value="Maint Details ->" name="lnkSubmit"> 
            </td> 
        </tr> 
    </table> 
</div> 

And here's the test code:

        HtmlInputSubmit maintDetailsButton = Find.ByAttributes<HtmlInputSubmit>("value=Maint Details ->"); 
        maintDetailsButton.Click(); 

        Assert.IsTrue(ActiveBrowser.Url.Contains(expectedPage), "URL {0} does not contain expected page {1}", ActiveBrowser.Url, expectedPage); 

The sequence of operations is working just fine when I click it manually, so I can see no evidence that it's the site's problem. I've seen abundant evidence that it is, in fact, clicking the "Back" button and not the "Maint Details" button. (Fiddler shows no request issued when the click request is sent - consistent with executing history.back(), since the browser simply redisplays from it's cache. When I click, it does, in fact, go to the previous page. And finally, if I remove the "onclick" attribute from the back button, so that clicking on the button does nothing, then when execute the test code, the site does nothing - simply stays on the current page.)

I am completely baffled. Can anyone give me a hint?

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

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

发布评论

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

评论(1

绾颜 2024-09-14 11:20:37

好吧,我花了一个星期的时间把头撞在墙上,但我确实明白了这一点。

首先,我发现了一些事情。根据我的推断,当您执行 Find. 操作时,WebAii 会将该元素作为索引跟踪到文档中该类型的所有元素的列表中。然后,每当您访问找到的元素时,WebAii 都会生成“document.GetElementsByTag('')[]”形式的 JavaScript 函数。当我试图找到一种方法来识别 WebAii 找到的元素时,我意外地发现了这一点,并无意中生成了一个 JavaScript 错误,该错误显示了它试图在异常中执行的函数。
因此,然后我推断,如果它通过索引访问元素,并且不知何故其索引关闭,那么它在我想要的元素之前单击输入元素是有意义的。
因此,我执行了 Find.AllByTagName("input"),并在 VS 调试器中查看了生成的 ReadOnlyCollection,并开始将它找到的输入元素与我在查看页面的“查看源代码”时可以识别的内容进行匹配。我发现我发现 WebAii 没有列出一个,位于页面顶部附近,并且经过仔细检查发现缺少的输入元素缺少它的右尖括号。
所以,显然 WebAii 没有发现它作为输入元素,但 javascript 发现了。因此,当我的测试说“maintDetails.Click()”时,它会被转换为类似“document.GetElementsByTag('input')[20].click()”的内容,而由于缺少元素,它应该是“document.GetElementsByTag('input')[21].click()”。

我修复了站点源代码中缺少的右尖括号,然后测试运行了。

Well, it's taken me a week of beating my head against the wall, but I did figure this out.

First, I discovered something. From what I've been able to deduce, when you do a Find., WebAii keeps track of that element as an index into a list of all the elements of that type in the document. Then, whenever you access a found element, WebAii will generate a JavaScript function of the form "document.GetElementsByTag('')[]." I discovered this accidentally when I trying to find a way to identify the element that WebAii had found, and inadvertently generated a javascript error which displayed the function it was trying to execute in the exception.
So, then I reasoned that if it's accessing the element by index, and somehow or another its index is off, then it would make sense that it was clicking the input element before the one I wanted it to.
So I did a Find.AllByTagName("input"), and looked through the resulting ReadOnlyCollection in the VS debugger, and started matching the input elements that it found with what I could identify looking at a View Source of the page. I discovered that I was finding one that WebAii wasn't listing, way up near the top of the page, and, on closer examination discovered that the input element that was missing was missing it's closing angle bracket.
So, apparently WebAii did not find that as an input element, but javascript did. So when my test said "maintDetails.Click()", that was being converted into something like "document.GetElementsByTag('input')[20].click()", when, because of the missing element, it should have been "document.GetElementsByTag('input')[21].click()".

I fixed up the missing closing angle bracket in the site source code, and the test ran.

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