PageFactory: FindBy and By initialisation

33 views
Skip to first unread message

jonas

unread,
Apr 25, 2019, 7:46:57 AM4/25/19
to Selenium Users
Hi,

I am asking myself if I am on the right track:

I have pages which are initialized with PageFactory. The static elements, I describe with FindBy annotation. This works fine.
However, on this pages can be tables (sometimes many).

The tables have filtering, column selection, row selection etc. The tables are always built the same way and have the same elements. I started to build the locators with FindBy, but that seems tedious and that for each table, each element etc. Simplified it could look like this:

@FindBy(css="div[id*='tableName1'] div[class='filterOpen']")
WebElement filterOpen;

@FindBy(css="div[id*='tableName1'] div[class='openedFilter'] div[class=''apply]")
WebElement filterApply;

@FindBy(css="div[id*='tableName2'] div[class='filterOpen']")
WebElement filterOpen;

@FindBy(css="div[id*='tableName2'] div[class='openedFilter'] div[class=''apply]")
WebElement filterApply;

If anything changes in the table build (e.g. in the tableName part), I need to adapt all annotations.

Therefore, I created a class where I build up these locator strings in a general way. I use them to replace tableName and return a By element, which I can user for further actions.

//Table (Header)
String tableHeader = "div[id*='+|tableName+|']";
String tableColumnHeader = tableHeader+" div[data-col-id='"+columnName+"']";
String tableFilterOpen = tableHeader+" div[class='filterOpen']";
etc.

public TableLocators(String tableN) {
tableName = tableN;
}

public By getByTableHeader(){
return By.cssSelector(replaceTableName(tableHeader ));
}
etc.

Again, this is simplified, but I hope, you get the strategy.

But I am asking myself: Is this really the proper way to do it? On top I am having a mixture of static FindBy elements and dynamic elements. But that seems ok according to other posts.

Thank you for your answer.
Jonas



poobathy r

unread,
Apr 25, 2019, 7:52:00 AM4/25/19
to seleniu...@googlegroups.com
Please post the HTML view..we can find a better solution for this..

Regards
Poobathy

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/d82fcc14-6492-4412-a1ea-6931ee72e65c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages