我正试图通过Cheezy的pageobject访问字段集中的select_list。
总的html太长了,不能发布(只有字段集超过200行),但我可以提供所有id等的行。
字段集:
<fieldset class="dartPayer-Insurance" style="width: 730px;">
select_list中:
<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>'
答案 0 :(得分:2)
解决方案
您选择列表所需的访问者是:
select_list(:payer_insurance){ element(:fieldset, :class => "dartPayer-Insurance").select_list_element(:id => "dartPayer-Payer") }
问题
由于以下部分,您收到了语法错误:
element(:class => "dartPayer-Insurance")
在API docs for 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
。