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();
}
}
我只是想自动化ibibo网站。我正在获取上述代码的nullpointer异常。我无法理解传递空值的位置。请帮忙。谢谢
答案 0 :(得分:0)
答案 1 :(得分:0)
进行以下更改:
IbiboHomePage home = PageFactory.initElements(driver, com.Nalini.Ibibo.IbiboHomePage.class);
IbiboHomePage home = PageFactory.initElements(driver, IbiboHomePage.class);
您可以从static
static WebDriver driver;
删除public class IbiboTest
在public class IbiboHomePage
中将WebDriver的实例声明为:
WebDriver driver;
public IbiboHomePage(WebDriver driver)
中删除行PageFactory.initElements(driver, this);
执行代码并更新状态。