Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessors for multiple elements #144

Closed
p0deje opened this issue Nov 22, 2012 · 8 comments
Closed

Accessors for multiple elements #144

p0deje opened this issue Nov 22, 2012 · 8 comments

Comments

@p0deje
Copy link
Contributor

p0deje commented Nov 22, 2012

Hi!

I've been thinking about the ways to do smth like this

class Page
  include PageObject

  divs :history_divs, class: 'history'

  def history_notes
    history_divs_elements.map(&:text)
  end
end

Is multiple elements accessors are possible or planned?

@wjpowell
Copy link
Contributor

I haven't verified this, but can't you already accomplish the same thing with this?

  def history_notes
    div_elements(:class=> 'history').map(&:text)
  end

@p0deje
Copy link
Contributor Author

p0deje commented Nov 26, 2012

It works, but it's not much different from watir:

def history_notes
  browser.divs(:class => 'history').map(&:text)
end

and I'd want to be able to define elements in a single place (section of page-object accessors calls) to keep page classes well-organized.

@cheezy
Copy link
Owner

cheezy commented Dec 20, 2012

The form that @wjpowell showed works just fine. I really do not see the need to add another set of methods that generate other methods when it is very simple to get what you want with the existing api.

@p0deje
Copy link
Contributor Author

p0deje commented Dec 20, 2012

I know that it works. However, one of the advantages of page-object is that it makes page classes very structured because literally all the elements are defined using class methods and are in the beginning of class. Without accessors to multiple elements, you have to define elements in instance methods.

That's IMO and may be irrelevant, so just close the issue if you think it doesn't worth :)

@cheezy
Copy link
Owner

cheezy commented Dec 22, 2012

I've added this to the gem. It will go out with the release I have planned for later today.

@cheezy cheezy closed this as completed Dec 22, 2012
@p0deje
Copy link
Contributor Author

p0deje commented Dec 23, 2012

Thanks!

@swaroop-tata
Copy link

If i have 3 divs with same class name. How do i access the first div's text?

@gabyshev
Copy link

gabyshev commented Sep 3, 2014

@swaroop-tata You can get particular div with index property.

div(:my_div, class: 'common-class', index: 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants