Selenium 无法验证我的应用程序中的弹出式覆盖

Selenium 无法验证我的应用程序中的弹出式覆盖,selenium,nullpointerexception,Selenium,Nullpointerexception,我正在使用SeleniumWebDriver,它使用Cucumber 我点击了一个按钮,打开了一个弹出框,里面包含了一些web元素。我需要在这个弹出框中执行一些验证。但一旦显示覆盖弹出窗口,我就无法使用isDisplayed对其进行验证 在控制台中,它会显示一条错误消息-java.lang.NullPointerException,但我不会在任何变量中传递任何值来验证这个弹出框 我的脚本如下: public static void Popupbox() { searchbox =

我正在使用SeleniumWebDriver,它使用Cucumber

我点击了一个按钮,打开了一个弹出框,里面包含了一些web元素。我需要在这个弹出框中执行一些验证。但一旦显示覆盖弹出窗口,我就无法使用isDisplayed对其进行验证

在控制台中,它会显示一条错误消息-java.lang.NullPointerException,但我不会在任何变量中传递任何值来验证这个弹出框

我的脚本如下:

    public static void Popupbox() {
    searchbox = (Application_Pagexpath.popupboxheader).isDisplayed();

    try{
        Thread.sleep(100);
        }catch(InterruptedException e){
        e.printStackTrace();    }

    if(searchbox = True) {
    System.out.println("Popup is displayed"); } 
}
div id="_paymentHistoryPortlet_WAR_EBillingWebportlet_:paybillHtyForm:dvAdvSearchOverlay" class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-shadow ebillingAdvFltrOverlay ui-draggable ui-overlay-visible" style="width: auto; height: auto; left: 227.7px; top: 0px; visibility: visible; z-index: 1001;" role="dialog" aria-labelledby="_paymentHistoryPortlet_WAR_EBillingWebportlet_:paybillHtyForm:dvAdvSearchOverlay_title" aria-hidden="false" aria-live="polite"
  div class="ui-dialog-titlebar ui-widget-header ui-helper-clearfix ui-corner-top"
    div class="ui-dialog-content ui-widget-content" style="height: auto;"
我使用的XPath是正确的,并且在firebug中工作良好。您能帮助我理解为什么我看到空指针异常错误,以及为什么Selenium无法验证这个覆盖弹出窗口吗

覆盖弹出窗口的HTML如下所示:

    public static void Popupbox() {
    searchbox = (Application_Pagexpath.popupboxheader).isDisplayed();

    try{
        Thread.sleep(100);
        }catch(InterruptedException e){
        e.printStackTrace();    }

    if(searchbox = True) {
    System.out.println("Popup is displayed"); } 
}
div id="_paymentHistoryPortlet_WAR_EBillingWebportlet_:paybillHtyForm:dvAdvSearchOverlay" class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-shadow ebillingAdvFltrOverlay ui-draggable ui-overlay-visible" style="width: auto; height: auto; left: 227.7px; top: 0px; visibility: visible; z-index: 1001;" role="dialog" aria-labelledby="_paymentHistoryPortlet_WAR_EBillingWebportlet_:paybillHtyForm:dvAdvSearchOverlay_title" aria-hidden="false" aria-live="polite"
  div class="ui-dialog-titlebar ui-widget-header ui-helper-clearfix ui-corner-top"
    div class="ui-dialog-content ui-widget-content" style="height: auto;"

你试过调试你的代码吗?你得到的是哪一行空指针?可能是空指针异常,因为它无法确定.isDisplayed,除非找到web元素本身。将该行分成两行:一行用于分配web元素,另一行用于测试isDisplayed,但仅当web元素不为null时。如果它是空的,可以肯定地说它不会显示。嗨,Ranjith,我只在siDisplayed行看到空指针异常。Bill,感谢您研究这个问题并提供解决方案。根据您的要求,我将这行代码分为2行-一行用于分配web元素,另一行用于测试isDisplayed。但在第一轮中,它没有起作用。在第二次运行期间,我将睡眠线程中的时间增加到5000毫秒,这一次起作用了。再次感谢。