I get the exception
java.lang.RuntimeException: java.lang.IllegalAccessException: Class org.openqa.selenium.support.PageFactory can not access a member of class moronicpackage.GoogleSearchPage with modifiers ""

The exception was being thrown because of incorrect documentation in the Selenium reference. I used the following syntax for initialization of the page and it worked fine.
–
Ashish NarmenDec 14 '11 at 9:16

4 Answers
4

I was calling PageFactory.initElements incorrectly. The second argument needed to be a GoogleSearchPage instance rather than the GoogleSearchPage class object. The main method needed to look like this:

There is nothing wrong with documentation. Need to specify page object classes as public classes.So moving GoogleSearchPage to different file and specifying it as public class should work fine. the way suggested here is also correct but is just an alternative.