Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I tried running the following code to start running Selenium WebDriver on Java, using the following code

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.*;
public class Runner 
{

    public static void main(String[] args) 
    {

        WebDriver driver;
        driver = new InternetExplorerDriver();
        driver.get("http://www.google.co.in");
        try
        {/// Exception thrown on initElements

            GoogleSearchPage page1 = PageFactory.initElements(driver, GoogleSearchPage.class);


            page1.SearchFor("hu ha 123");
        }
        catch(Exception excp)
        {
            System.out.println(excp.toString());
        }
        driver.quit();
    }

}

class GoogleSearchPage
{
    @FindBy(how = How.NAME, using = "q")
    public WebElement searchbox;

    public void SearchFor(String Text)
    {
        searchbox.sendKeys(Text);
        searchbox.submit();
    }
}

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 ""

Any ideas?

share|improve this question
    
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 Narmen Dec 14 '11 at 9:16

3 Answers 3

public class Create_User {
    WebDriver driver;

    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
    capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
    driver = new InternetExplorerDriver(capabilities); 
    driver.get(getProperty("www.google.co.in"));
}
share|improve this answer
    
Do this one for internet explorer.its working fine –  santosh Jun 5 '12 at 8:30
up vote 0 down vote accepted

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:

    public static void main(String[] args) 
{
    WebDriver driver;
    driver = new InternetExplorerDriver();
    driver.get("http://www.google.co.in");
    try
    {
        GoogleSearchPage page1 = new GoogleSearchPage();
        PageFactory.initElements(driver, page1);        
        page1.SearchFor("hu ha 123");
    }
    catch(Exception excp)
    {
        System.out.println(excp.toString());
    }

    driver.quit();
}
share|improve this answer
    
Ok, I have added the response as a comment to the answer too. –  Ashish Narmen Dec 14 '11 at 9:23
    
Ashish, can you to mark this answer as the best one? Just click the checkmark next to the vote count. –  user246 Feb 9 '12 at 23:34

Try making your GoogleSearchPage class public. Instead of this:

class GoogleSearchPage

do this:

public class GoogleSearchPage
share|improve this answer
    
Thanks for the response, but that did not make any difference at all. –  Ashish Narmen Dec 14 '11 at 9:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.