我有一个现有的页面对象模型代码,我需要在浏览器堆栈中运行我的代码,但是在我的测试方法内部,对于调用的对象方法却得到了空指针异常。
如果我使用driver.findElement在测试方法中直接添加X路径,则元素会被单击,但是当我从页面工厂导入对象引用时,会出现空指针异常
public class Office_Application_page extends TestBase {
public Office_Application_page() {
PageFactory.initElements(driver, this);
}
@FindBy(xpath="//button[@class='gdpr-modal-close']")
WebElement close_btn;
public class Office_Application_test {
private WebDriver driver;
Questions_id3_Page Qpage1;
Office_Application_page Office1;
String sheetName = "Application1";
TestUtil testUtil;
public Office_Application_test(){
super();
}
@BeforeClass
public void setUp() throws InterruptedException,
MalformedURLException {
testUtil = new TestUtil();
Office1 = new Office_Application_page();
Qpage1 = new Questions_id3_Page();
DesiredCapabilities capability = new DesiredCapabilities();
capability.setPlatform(Platform.WINDOWS);
("build", "TestNG - Sample1");
driver = new RemoteWebDriver(
new URL("https://venkateshkv2:fivhxapgnazGspyJTPnn@hub-
cloud.browserstack.com/wd/hub"),
capability);
}
@Test(priority=3, dataProvider="getApplicationTestData")
public void Enters() throws
FindFailed,InterruptedException,MalformedURLException{
driver.get("URL");
Thread.sleep(2000);
Office1.ClickonCloseBtn();