Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

WebDriver: Improvement - extend PageFactory to support List<WebElement> #417

Closed
lukeis opened this issue Mar 2, 2016 · 12 comments
Closed

Comments

@lukeis
Copy link
Member

lukeis commented Mar 2, 2016

Originally reported on Google Code with ID 417

The PageFactory currently only supports a single WebElement in the
ElementLocator interface.  It would be great if it could be extended to
also support a List of WebElement, as returned by the driver.findElements()
method.

As an example, the construct 

   lineNumbers = driver.findElements(By.name("lineNumber"))

could be represented as:

    @FindAllBy(how = How.NAME, using = "lineNumber")
    private List<WebElement> lineNumbers

Thanks for your great work with WebDriver!


What version of the product are you using? 

    "org.seleniumhq.webdriver:webdriver-support:0.9.7376"


Reported by nigel.charman.nz on 2010-03-10 10:48:56

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by jmleyba on 2010-04-11 18:27:53

  • Labels added: Type-Enhancement
  • Labels removed: Type-Defect

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by jari.bakken on 2010-06-16 23:51:42

  • Labels added: Component-WebDriver, Lang-Java

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by simon.m.stewart on 2010-09-09 22:09:43

  • Labels added: NextRelease

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Dropping from NextRelease due to time issues.

Reported by simon.m.stewart on 2010-10-06 10:14:49

  • Labels removed: NextRelease

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Picking this one up in the Bug Bash

Reported by simon.m.stewart on 2011-01-24 13:23:49

  • Status changed: Started

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I logged a duplicate of this issue in issue 1602.

I'll copy one of my comments from there in here.  You're likely already aware of this
trick, but just in case...

When I first tried to do this, I noticed that you block against non WebElement fields
being used, which is perfectly understandable.  Obviously, using List<WebElement> poses
a problem of inferring the generic type to make sure it's compatible.  You're probably
already well aware of the following technique for getting around that limitation, but
I'll cover it in this ticket if for some reason it's not well known.  You can maintain
reification through extension; if you were to make an interface type of WebElementList
that extended List<WebElement>, you can be sure of the generic type.

Reported by ian.g.simpson on 2011-05-11 17:24:53

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Issue 1602 has been merged into this issue.

Reported by jmleyba on 2011-05-12 18:39:55

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

This issue was closed by revision r14014.

Reported by barancev on 2011-10-04 13:57:42

  • Status changed: Fixed

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Thanks a lot for making this change!

I was just looking at the JavaDoc for FindAllBy. Shouldn't the following line use List<WebElement>
rather than WebElement?

@FindAllBy(how = How.TAG_NAME, using = "a") WebElement links;

Reported by nigel.charman.nz on 2011-10-04 18:47:43

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Thank you, fixed!
One more thing to mention: we've decided to use the same annotation:

@FindBy(tagName = "a") List<WebElement> links;

Reported by barancev on 2011-10-04 18:59:52

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Hi. Unfortunately this has broken some of our existing Page Objects, since it is applied
to Lists that don't have the annotation.  For example:

  List<String> headings;

I've created a new issue http://code.google.com/p/selenium/issues/detail?id=2674 with
more details.

Reported by nigel.charman.nz on 2011-10-17 08:08:13

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by luke.semerau on 2015-09-17 17:48:57

  • Labels added: Restrict-AddIssueComment-Commit

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

No branches or pull requests

1 participant