Question

I'm trying to use Cheezy's page-object gem for everything in order to be consistent. However I haven't been able to find how to drill down to an element like this. The situation here is that there would be more than one link with all the same tags so you have to drill down from something identifiable.

@browser.p(:text => /#{app_name}/i).link(:text => 'Add').click

The code I'm looking for would be something like this to click on a link located inside of a paragraph but it doesn't work.

p(:pgraph, id: => 'some-pgraph')
link(:lnk, text: => 'add')    

self.pgraph.lnk

Is there a way to do this with page object?

Thanks, Adam

Was it helpful?

Solution

You can use blocks to define accessors with more complicated locating strategies.

If you want to also keep a reference to the paragraph:

p(:pgraph, id: 'some-pgraph')
link(:lnk){ pgraph_element.link_element(text: 'add') }

Or if you do not need the paragraph for other things, you might do:

link(:lnk){ paragraph_element(id: 'some-pgraph').link_element(text: 'add') }    

Basically you can use a block with nested elements, to define accessors similar to how you would in Watir.

Note that if you want to specify the id dynamically at run time, you can always define a method to click the link instead of using the accessors:

def click_link_in(paragraph_id)
  paragraph_element(id: paragraph).link_element(text: 'add').click
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top