-1
public class IbiboTest {

static WebDriver driver;

@BeforeClass
public void setUp() throws InterruptedException{
    System.setProperty("webdriver.chrome.driver","C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();

    //driver= new FirefoxDriver();
    driver.get("https://www.goibibo.com/");
    Thread.sleep(5000);
    driver.manage().window().maximize();

}


@Test
public void testIbiboHomePage(){
    IbiboHomePage home = PageFactory.initElements(driver, com.Nalini.Ibibo.IbiboHomePage.class);
    home.clickRoundTripRadioButton();

}

public class IbiboHomePage {

WebDriver driver;
@FindBy(css = "input[id='gi_roundtrip_label']")
WebElement iRoundTrip;


public IbiboHomePage(WebDriver driver){
    this.driver = driver;
    PageFactory.initElements(driver, this);

}

public void clickRoundTripRadioButton(){
iRoundTrip.click();
}

}

I am just trying to automate ibibo website.I am getting nullpointer exception for the above code.I am not able to understand where it is passing a null value.Pls help.Thank you

Nal
  • 3
  • 1
  • 4

2 Answers2

0

Seems to be the same problem as this previous post

How to use @FindBy annotation in Selenium WebDriver

Take a look about the @findby and @beforeclass execution order.

Community
  • 1
  • 1
e1che
  • 1,241
  • 1
  • 17
  • 34
0

Make the following change:

  1. Replace IbiboHomePage home = PageFactory.initElements(driver, com.Nalini.Ibibo.IbiboHomePage.class);

with IbiboHomePage home = PageFactory.initElements(driver, IbiboHomePage.class);

  1. You can remove static from static WebDriver driver; in public class IbiboTest

  2. In public class IbiboHomePage declare the instance of WebDriver as :

WebDriver driver;

  1. From the constructor public IbiboHomePage(WebDriver driver) remove the line PageFactory.initElements(driver, this);

Execute the code and update me the status.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352