Re: Defining a method to click on an element

29 views
Skip to first unread message

Jason Hansen

unread,
May 22, 2014, 1:47:02 PM5/22/14
to Mike Rose, page-...@googlegroups.com
In your first example, when you are identifying elements from inside a method, you need to use the *_element methods.  So instead of:

  def go_to_store
    div(:class => "nav-inner1").li(:class => "expanded store dropdown").a(:index, 0).click
  end

You should use:

  def go_to_store
    div_element(:class => "nav-inner1").list_item_element(:class => "expanded store dropdown").link_element.click
  end

In your second example, you can't chain the page elements you define at the top of the page together.  Meaning, you can't do:

div :div_a, :id => "a"
div :div_b, :id => "b"

def asdf
  div_a.div_b.click
end

Can your go_to_store method simply start with the store_tab element?  Like:

def go_to_store
  store_tab.link_element.click
end

Also, you might run into issues trying to identify elements using compound CSS classes.  You may need to identify the store tab with something like

li(:store_tab, :css => ".extended.store.dropdown")


Jason



On Thu, May 22, 2014 at 11:28 AM, Mike Rose <mike...@gmail.com> wrote:
So, im running into a silly issue trying to define a method inside my page class that will basically click on a link for me. I get an error that the method "div" isnt defined. I have tried defining in the page object, but then I get an error that the method "li" isnt defined., WHen I define "li" in the page class, Im still getting the same error on the "li" method. I have to go one element deeper to get it to work. Here is the action that works..
   
    When(/^I click on the Store tab$/) do
  @browser.div(:class => "nav-inner1").li(:class => "expanded store dropdown").a(:index, 0).click

I am trying to define that in a method inside my page class as follows..

    class MainPage
  include PageObject


  def go_to_store
    div(:class => "nav-inner1").li(:class => "expanded store dropdown").a(:index, 0).click
  end
end

I have tried something like this...

    class MainPage
  include PageObject


  div(:top_tab, :class => "nav-inner1")
  li(:store_tab, :class => "extended store dropdown")

  def go_to_store
    top_tab.store_tab.a(:index, 0).click
  end
end

But I get an error that "store_tab" is undefined. So it seems to like top_tab, but not store_tab. As you can see in the first code snippet, i still have an "a" element to get through to be able to click. 

Any suggestions on how to get this simple method to work? Its prolly something simple that I am missing. 



Dane Andersen

unread,
May 22, 2014, 3:50:47 PM5/22/14
to Jason Hansen, page-...@googlegroups.com, Mike Rose

Also, if you are accessing the element, you have to use store_tab_element. store_tab will return the text inside that div, but store_tab_element returns the div element for you to perform actions on and whatnot.

Reply all
Reply to author
Forward
0 new messages