Firewatir:Firewatir 脚本从下拉列表中选择一个项目

发布于 2024-09-27 00:14:34 字数 778 浏览 6 评论 0原文

我是 Watir 自动化测试的新手,希望获得一些有关下拉菜单的帮助。在我们的网站上,我们有一个州下拉菜单,您可以在其中输入州的第一个字母(在我的示例中,C 代表加利福尼亚州),它会缩小范围找到以 C 开头的所有州。获得列表后,您需要单击正确的州。但我很难选择正确的状态。

(下面是我们网站上的 html:


<div class="x-form-field-wrap x-trigger-wrap-focus" id="ext-gen202" style="width: 166px;">
<input type="hidden" id="entityStateCode" name="entityStateCode" value="">
<input type="text" id="ext-comp-1005" autocomplete="off" size="24" class=" x-form-text x-form-field x-form-focus">

我使用以下内容来自动化该场景,但这些都没有给我我想要的东西:

@browser.text_field(:id,"ext-comp-1005").value=( "CA")

@browser.text_field(:id,"ext-comp-1005").set("CA")

@browser.text_field(:id=> "ext-comp-1055",:index =>; 5).set“CA”

如果您能为我指明正确的方向,我真的很感激

I am new to Watir automation testing and would like to get some help for the drop down.On our website we have a state drop down where you enter the first letter of the state (in my example C for California) and it narrows it down to the all states starting with C. Once you have the list you need to click on the correct state. But I am having difficulties selecting the correct state.

(Below is the html from our website:


<div class="x-form-field-wrap x-trigger-wrap-focus" id="ext-gen202" style="width: 166px;">
<input type="hidden" id="entityStateCode" name="entityStateCode" value="">
<input type="text" id="ext-comp-1005" autocomplete="off" size="24" class=" x-form-text x-form-field x-form-focus">

I used the following to automate the scenario but none of these are giving me what i am looking for:

@browser.text_field(:id,"ext-comp-1005").value=("CA")

@browser.text_field(:id,"ext-comp-1005").set("CA")

@browser.text_field(:id=> "ext-comp-1055",:index => 5).set "CA"

I really appreciate that if you can point me to the right direction.

Thanks

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

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

发布评论

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

评论(2

木槿暧夏七纪年 2024-10-04 00:14:34

我以前遇到过类似的情况。在我的情况下,DIV 中有一个表,动态下拉列表中的每个项目都有一个单独的行。因此,如果您遇到这种情况,那么您需要使用类似的方法来访问这些项目:

@browser.text_field(:id,"ext-comp-1055").set "C"
table = @browser.div(:id, "ext-gen336").table(:index, 1)
puts "First entry value: #{table[1][1].text}"
table[2][1].click  # second entry

尝试在运行时打印 DIV 的 HTML,以查看您需要交互的具体内容(如果这不起作用)。

I ran into a similar situation before. In my situation there was a TABLE inside the DIV which had a separate row for each item in the dynamic drop down. So, if that's the case for you then you would need to use something like this to access the items:

@browser.text_field(:id,"ext-comp-1055").set "C"
table = @browser.div(:id, "ext-gen336").table(:index, 1)
puts "First entry value: #{table[1][1].text}"
table[2][1].click  # second entry

Try printing out the HTML for the DIV at runtime to see the specifics of what you need to interact with if that doesn't work.

兮颜 2024-10-04 00:14:34

你没有说出问题是什么,这还不够:

这些都没有给我现在的样子
寻找

This should Enter CA into text field:

browser.text_field(:id => "ext-comp-1005").set("CA")

如果在错误的文本字段中输入文本,请更改 :id =>; “ext-comp-1005”

如果它正在将文本输入到正确的文本字段中,但没有出现状态列表,则您可能必须触发一些 javascript 事件。查看如何找出触发了哪些 JavaScript 事件? 问题。

You did not tell what the problem is, this is not enough:

none of these are giving me what i am
looking for

This should enter CA into text field:

browser.text_field(:id => "ext-comp-1005").set("CA")

If it is entering text into wrong text field, change :id => "ext-comp-1005".

If it is entering text into the correct text field, but list of states does not appear, you probably have to fire some javascript event. Take a look at How to find out which JavaScript events fired? question.

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