Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between @FindAll and @FindBys annotations in webdriver page factory

Please explain the difference between @FindAll and @FindBys annotations in webdriver page factory concept.

like image 669
Vikas Avatar asked Sep 18 '14 13:09

Vikas


People also ask

What is the use of @FindBy annotation?

Annotation Type FindBy Used to mark a field on a Page Object to indicate an alternative mechanism for locating the element or a list of elements. Used in conjunction with PageFactory this allows users to quickly and easily create PageObjects. It can be used on a types as well, but will not be processed by default.

Which is the correct syntax for @FindBy annotation?

@FindBy(how = How.NAME, using = "logonName") private WebElement logonNameField; @FindBy(how = How.NAME, using = "password") private WebElement passwordField; CLASS_NAME. CSS. ID.

What is @FindBy in Pom?

The annotation @FindBy is used in Pagefactory to identify an element while POM without Pagefactory uses the driver. findElement() method to locate an element.


2 Answers

We can use these annotations in those cases when we have more than a single criteria to to identify one or more WebElement objects.

@FindBys : When the required WebElement objects need to match all of the given criteria use @FindBys annotation

@FindAll : When required WebElement objects need to match at least one of the given criteria use @FindAll annotation

Usage:

@FindBys( {
   @FindBy(className = "class1")
   @FindBy(className = "class2")
} )
private List<WebElement> elementsWithBoth_class1ANDclass2;

Here List elementsWithBothclass1ANDclass2 will contain any WebElement which satisfies both criteria.

@FindAll({
   @FindBy(className = "class1")
   @FindBy(className = "class2")
})
private List<WebElement> elementsWithEither_class1ORclass2  

Here List elementsWithEither_class1ORclass2 will contain all those WebElement that satisfies any one of the criteria.

like image 96
san1deep2set3hi Avatar answered Oct 18 '22 21:10

san1deep2set3hi


@FindAll can contain multiple @FindBy and will return all the elements which matches any @FindBy in a single list.

Example:

@FindAll({
@FindBy(id = "one"),
@FindBy(id = "two")
})
public List<WebElement> allElementsInList;

Whereas,

@FindBys will return the elements depending upon how @FindBy specified inside it.

 @FindBys({
    @FindBy(id = "one"),
    @FindBy(className = "two")
    })
    public List<WebElement> allElementsInList;

Where allElementsInList contains all the elements having className="two" inside id="one"

like image 30
2 revs, 2 users 96% Avatar answered Oct 18 '22 19:10

2 revs, 2 users 96%