Question

I'm trying to access a select_list within a fieldset though Cheezy's pageobject.

The total html is far too long to post (well over 200 lines for just the fieldset), but I can supply the lines with all of the id's and such.

fieldset:

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

select_list:

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

Line in the pageobject I am attempting to use:

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

The error I am getting when I try to run my cucumber test:

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

This error occurs when I try to set the select_list with this line:

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

This line works for other pages, so I am fairly certain this is not part of the problem. I'm sure it's a simple bit of syntax in the pageobject line, but I can't find any documentation for using the pageobject quite like I'm trying to. The only reference I can find is within a previous question I asked: Accessing a table within a table (Watir/PageObject)

Could anyone please tell me what I have done wrong?

Thank you in advance for your help.

Update: An example that reproduces the problem:

Given a page with the html:

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

And a page object defined as:

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

Running the following code:

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)

Generates the following exception:

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>'
Was it helpful?

Solution

Solution

The accessor you want for the select list is:

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

Problem

You were getting the syntax error due to the following part:

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

In the API docs for element, you can see that method definition is:

(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

The original code was missing the tag parameter, which caused the exception.

Note that the select list id was also incorrect - using dartPayer-PayerList instead of dartPayer-Payer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top