使用 Watir(或 WatiN 或类似)进行自动化测试:消除选择元素的歧义

发布于 2024-07-11 15:56:27 字数 408 浏览 12 评论 0原文

问题:我正在寻找一种运行测试的方法,该方法能够消除在多个位置具有相同值的选择控件之间的歧义。

示例:

我试图从选择控件中选择第三个“星期一”,

ie.select_list( :id , 'choose-day' ).set( '-monday' );

其中选择控件在控件本身中具有一种“大纲”格式:

alice
-monday
-tuesday
bob
-monday
-tuesday
charlie
-monday
-tuesday

鉴于文本是相同的(并且我确实这样做)不知道提前的选项值是什么)有没有一种方法可以对测试进行编码,以便查理下的星期一被选中?

Problem: I am looking for a way to run a test that is able to disambiguate between select controls that have the same value in more than one place.

Example:

I am trying to choose the third "monday" from a select control

ie.select_list( :id , 'choose-day' ).set( '-monday' );

where the select control has a kind of "outline" format in the control itself:

alice
-monday
-tuesday
bob
-monday
-tuesday
charlie
-monday
-tuesday

Given that the text is identical (and I do not know what the option values are ahead of time) is there a way to code the test such that the monday under charlie is the one that gets selected?

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

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

发布评论

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

评论(2

分开我的手 2024-07-18 15:56:27

在 WatiN 中,您可以利用多属性支持来匹配元素(我认为 Watir 中也提供类似的功能)。

Option option = ie.SelectList("choose-day").Options(Find.ByText("-monday") && Find.ByIndex(2))

(索引是从零开始的,所以 2 将给出第三个匹配项(如果任何))。

哈特哈,
杰罗恩·范梅宁
首席开发人员等待

In WatiN you can make use of multiple attribute support to match an element (I thought something similar is also available in Watir).

Option option = ie.SelectList("choose-day").Options(Find.ByText("-monday") && Find.ByIndex(2))

(index is zero based so 2 will give the third match (if any)).

HTH,
Jeroen van Menen
Lead dev WatiN

最舍不得你 2024-07-18 15:56:27

看起来您可以使用 element_by_xpath 来查找您想要的选项,如下所示:

//select/option[text()='charlie']/following::option[text()='-monday']

然后您可以检查该选项的 value 属性(不知道如何在 Watir 中执行此操作),然后使用以下命令选择它:

ie.select_list( :id , 'choose-day' ).select_value( whatever_the_value_was );

It looks like you could use element_by_xpath to find the option you want, with something like this:

//select/option[text()='charlie']/following::option[text()='-monday']

then you could check the value attribute of that option (not sure how to do this in Watir), and select it using:

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