0
votes

In a previous script step, I updated the Previous Year Sales and am trying to confirm that the Gross Margin Dollar was correctly auto-updated to 650000. I am getting an error that watir is :

unable to locate element using id => "GrossMarginDollar", :tag_name => "input".

In a previous question, there was an answer that if there are multiple same-name elements, in this case span3, that watir picks the first one in the html, not the first one visible. If this is the problem, how can I specify which span3 to use? If this isn't the issue, what should I be using to confirm the value was updated?

Here is the watir script:

confirm = browser.div(:id => "target_modal").div(:class => "modal-body").div(:class => "row").div(:class => "span3").input(:id => "GrossMarginDollar")
puts confirm.value.include? '650000'

Here is the html:

<div class="row">
    <div class="span3">
        <label for="FirstName">First Name</label>
        <input id="FirstName" type="text" data-bind="value:FirstName" />
        <label for="LastName">Last Name</label>
        <input id="LastName" type="text" data-bind="value: LastName" />
        <label for="Email">Email</label>
        <input id="Email" type="text" data-bind="value: Email" />
        </select>
    </div>
    <div class="span1"></div>
    <div class="span3">
        <label for="PreviousYearSales">Previous Year Sales</label>
        <input id="PreviousYearSales" type="text" data-bind="value: PreviousYearSales" />
        <label for="GrossMarginDollar">Gross Margin Dollar</label>
        <input id="GrossMarginDollar" type="text" data-bind="value: GrossMarginDollar" />
    </div>
</div>
1

1 Answers

0
votes

You are right in that Watir is only checking the first div with class 'span3', which does not include the desired input field.

You can specify which match to use (ie the second match) but using the :index property. Note that the :index is 0-based, so "1" is actually the second matching div.

confirm = browser.div(:id => "target_modal").div(:class => "modal-body").div(:class => "row").div(:class => "span3", :index => 1).input(:id => "GrossMarginDollar")
puts confirm.value.include? '650000'

However, I think you are over specifying how to locate the element. In general, you want to use as little information as possible (as it makes the locator more robust to changes). In this case, you have an id of the input element. Given that the id should be unique, you should not need all of the other stuff. Simply do:

confirm = browser.input(:id => "GrossMarginDollar")
puts confirm.value.include? '650000'