使用 Watir(或 WatiN 或类似)进行自动化测试:消除选择元素的歧义
问题:我正在寻找一种运行测试的方法,该方法能够消除在多个位置具有相同值的选择控件之间的歧义。
示例:
我试图从选择控件中选择第三个“星期一”,
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 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
看起来您可以使用 element_by_xpath 来查找您想要的选项,如下所示:
然后您可以检查该选项的 value 属性(不知道如何在 Watir 中执行此操作),然后使用以下命令选择它:
It looks like you could use element_by_xpath to find the option you want, with something like this:
then you could check the value attribute of that option (not sure how to do this in Watir), and select it using: