Watir webdriver_Unable可以更改一个字段中的下拉列表并验证另一个字段中的值更改

时间:2013-11-21 23:08:21

标签: webdriver watir

感到沮丧的新用户有困难。尝试了许多变化,只是无法让它工作。 html在下面,我已经删除了额外的行。必须使用此html编写测试,我无法更改它。注意,类名为“span3”。

这是一个不是新窗口的弹出窗口,它似乎只是一个新窗口。顶部的“span3”是一个下拉列表,我正在尝试更改选择。我尝试在watir中使用select_list,但这不起作用。

在底部“span3”中,当我更改顶部“span3”中的下拉值时,将更新grossmarginpercent值。我想确认grossmarginpercent已更新为正确的值。

我已经包含了我尝试的最后一个脚本。我添加了一个put,因为我希望我在屏幕上看到'2',watir返回false,我想看看watir看到了什么。

watir脚本:

 grossmarginpercent = browser.div(:id => "target_modal").div(:class => "modal_body").div(:class => "row").div(:class => "span3", :index => 1).label(:id => "GrossMarginPercent")
      puts grossmarginpercent.value
             puts grossmarginpercent.value.include? '2'

HTML:

    <div class="modal-body">
        <div class="row">
            <div class="span3">
                <label>Reward Type</label><select data-bind="options: $root.RewardOptions, optionsText: 'DisplayName', value: RewardOptionId, optionsValue: 'RewardOptionId'"></select>
            </div>

            <div class="span1"></div>

            <div class="span3">
                <label>Gross Margin Percent</label><label id="GrossMarginPercent" data-bind="formattedNumber: { value: GrossMarginPercent, format: '#,###.##%' }" style="padding: 6px 4px 8px 0px;"></label>
            </div>
        </div>
    </div>

1 个答案:

答案 0 :(得分:0)

这在黑暗中有点刺,但我会尝试使用Element#text代替Element#value

puts grossmarginpercent.text
puts grossmarginpercent.text.include? '2'

我做了几个假设:

  1. 鉴于&#34;数据绑定&#34;属性,我猜你正在使用KnockoutJS(因为当我找到使用数据绑定属性的人时,这似乎是最受欢迎的搜索结果)。
  2. formattedNumber是一个自定义绑定,用于设置标签的文本。我假设您正在尝试检查您看到的内容,标签元素将是其文本而不是其值属性。