1

我有一个现有的页面对象模型代码,我需要在浏览器堆栈中运行我的代码,但是在我的测试方法中为调用的对象方法获取空指针异常。

如果我使用 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();
4

0 回答 0