Javascript 硒挂在环中

Javascript 硒挂在环中,javascript,selenium,xpath,Javascript,Selenium,Xpath,因为我在主页上有n个链接,每个链接都指向不同的应用程序。单击每个链接后将打开新的选项卡/窗口,在一个新选项卡中,我需要使用从excel为所有应用程序传递的元素的xpath检查特定元素的存在。在检查元素的存在后,我需要关闭子窗口并切换回父窗口,并按照相同的过程处理剩余的links1000+。只有当应用程序/窗口的非应用程序挂起时,我的脚本才能正常工作,如果任何应用程序未加载或挂起,则脚本无法关闭子窗口并切换回父窗口以继续使用其他链接进行测试 页面加载究竟是如何工作的? 我想在等待几秒钟后关闭子窗口

因为我在主页上有n个链接,每个链接都指向不同的应用程序。单击每个链接后将打开新的选项卡/窗口,在一个新选项卡中,我需要使用从excel为所有应用程序传递的元素的xpath检查特定元素的存在。在检查元素的存在后,我需要关闭子窗口并切换回父窗口,并按照相同的过程处理剩余的links1000+。只有当应用程序/窗口的非应用程序挂起时,我的脚本才能正常工作,如果任何应用程序未加载或挂起,则脚本无法关闭子窗口并切换回父窗口以继续使用其他链接进行测试

页面加载究竟是如何工作的? 我想在等待几秒钟后关闭子窗口,即使它正在加载页面并切换回父窗口
我曾经编写过一个实用程序类来处理窗口,并跟踪所有打开的窗口句柄。使用它,项目运行了4个打开的浏览器弹出窗口,然后按顺序关闭它们

这可能会有很大的改进,但下面是该类的一个示例方法:

/**
 * Loops to determine if WebDriver.getWindowHandles() returns any
 *  additional windows that the allHandles cache does not currently
 *  contain. If new window is found that is not in the cache, switch 
 *  to that latest window and update allHandles cache.
 */
public static String handleNewWindow() {
    String newHandle = "";
    printHandles();
    Set<String> updatedHandles = driver.getWindowHandles();
    if ( updatedHandles.size() < handleCache.size() ) {
        mainHandle = "";
        LOGGER.info("Illegal state: actually, I saw a window close.");
        throw new IllegalStateException("This method handleNewWindow is not appropriate\n" +
                "in this case.  You are probably looking for the\n"+
                "use of the updateHandleCache method.");
    } else if ( updatedHandles.size() == handleCache.size() ) {
        LOGGER.info("handleNewWindow() will do nothing because there are no new window handles.");
    } else {
        if ( !updatedHandles.isEmpty() ) {
            for ( String windowId : updatedHandles ) {
                if ( !windowId.equals( mainHandle ) ) { // for all windows except main window
                    if ( !handleCache.contains( windowId) ) { // for child windows not in allHandles cache
                        newHandle = windowId; // set value of newly found window handle                     
                        LOGGER.info("-- Open window handle: " + newHandle + " (new window)" );
                    }
                }
            }
            if ( !newHandle.equals("") ) { // outside loop so it catches latest window handle if there are multiple
                LOGGER.info("Switch to new window.");
                driver.switchTo().window( newHandle ); // switch to new window handle
            }
        } else {
            mainHandle = "";
            throw new IllegalStateException("No browser window handles are open.");
        }
    }
    handleCache = updatedHandles; // updates remembered set of open windows
    return newHandle;
}

嗨,Djangofan。。。在这里,我没有在窗口之间切换的问题。。如果任何子窗口挂起,selenium将停止在父窗口中执行更多链接。。如果没有任何窗口挂起,一切都可以正常运行。FF、chrome和IEF的问题在我看来,你只需要升级到更新版本的Selenium,以跟上最新浏览器的行为。另外,更新IE和Chrome二进制文件。我正在使用selenium 2.39,并将检查浏览器的更新二进制文件