Here is the code which Vance Zhao provided a way to find WebElements by reflection:
......
FSILoginPage landingpage =
PageFactory.initElements(driver, LoginPage.class);
Field f = landingpage.getClass().getDeclaredField("username");
WebElement e = new DefaultElementLocator(driver, f).findElement();
e.sendKeys("123456");
.....
Here is the PageObjects code:
public class LoginPage {
private WebElement username;
......
I will not consider to do this kind of coding in our test code , it is really a “Demo code”.
I will try to Abstract public methods in PageObjects Class which is a really worth stuff to do and make testing more fun and challenging! And also consider make WebElement to public as a workaround :)
