0

我试图通过 Cheezy 的页面对象访问字段集中的 select_list。

总的 html 太长而无法发布(仅字段集就超过 200 行),但我可以提供带有所有 id 等的行。

字段集:

<fieldset class="dartPayer-Insurance" style="width: 730px;">

选择列表:

<select id="dartPayer-Payer" style="width: 235px;">

我尝试使用的页面对象中的行:

select_list(:payer_insurance){ element(:class => "dartPayer-Insurance").select_list_element(:id => "dartPayer-PayerList") }

我尝试运行黄瓜测试时遇到的错误:

 (eval):1: syntax error, unexpected '(', expecting $end
  {:id=>"dartPayer-Insurance"}(identifier)
                               ^ (SyntaxError)

当我尝试使用此行设置 select_list 时会发生此错误:

self.send(field, input)  (Where field is "payer_insurance=" and input is "UMA")

这条线适用于其他页面,所以我相当肯定这不是问题的一部分。我确信这是 pageobject 行中的一个简单语法,但我找不到任何使用 pageobject 的文档,就像我正在尝试的那样。我能找到的唯一参考是在我问过的上一个问题中:Accessing a table within a table (Watir/PageObject)

谁能告诉我我做错了什么?

预先感谢您的帮助。

更新:重现问题的示例:

给定一个带有 html 的页面:

<fieldset class="dartPayer-Insurance" style="width: 730px;">
    <select id="dartPayer-Payer" style="width: 235px;">
        <option value="UMA">UMA</option>
    </select>
</fieldset>

一个页面对象定义为:

class MyPage
    include PageObject

    select_list(:payer_insurance){ element(:class => "dartPayer-Insurance").select_list_element(:id => "dartPayer-PayerList") }

    def input_payer(field, input)
        self.send(field, input)
    end
end

运行以下代码:

browser = Watir::Browser.new
browser.goto('C:\Scripts\Misc\Programming\PageObject\test.htm') 
page = MyPage.new(browser)

field = "payer_insurance="
input = "UMA"
page.input_payer(field, input)

生成以下异常:

C:/Ruby193/lib/ruby/gems/1.9.1/gems/page-object-0.9.0/lib/page-object/platforms/watir_webdriver/page_object.rb:968:in `instance_eval': (eval):1: syntax error, unexpected '(', expecting $end (SyntaxError)
{:class=>"dartPayer-Insurance"}(identifier)
                                ^
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/page-object-0.9.0/lib/page-object/platforms/watir_webdriver/page_object.rb:968:in `find_watir_element'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/page-object-0.9.0/lib/page-object/platforms/watir_webdriver/page_object.rb:907:in `element_for'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/page-object-0.9.0/lib/page-object/element_locators.rb:11:in `element'
from pageobject.rb:7:in `block in <class:MyPage>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/page-object-0.9.0/lib/page-object.rb:379:in `instance_eval'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/page-object-0.9.0/lib/page-object.rb:379:in `call_block'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/page-object-0.9.0/lib/page-object/accessors.rb:1089:in `block in standard_methods'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/page-object-0.9.0/lib/page-object/accessors.rb:246:in `block in select_list'
from pageobject.rb:10:in `input_payer'
from pageobject.rb:25:in `<main>'
4

1 回答 1

2

解决方案

选择列表所需的访问器是:

select_list(:payer_insurance){ element(:fieldset, :class => "dartPayer-Insurance").select_list_element(:id => "dartPayer-Payer") }

问题

由于以下部分,您收到了语法错误:

element(:class => "dartPayer-Insurance")

API 文档中element,您可以看到方法定义是:

(Object) element(tag, identifier = {:index => 0})

Finds an element

Parameters:
    the (Symbol) — name of the tag for the element
    identifier (Hash) (defaults to: {:index => 0}) — how we find an element. You can use a multiple paramaters by combining of any of the following except xpath

原始代码缺少tag参数,导致异常。

请注意,选择列表 id 也不正确 - 使用dartPayer-PayerList而不是dartPayer-Payer.

于 2013-07-29T13:26:51.203 回答