Selenium - 脚本应该等到浏览器手动关闭 [英] Selenium - Script should wait till browser is closed manually

查看:1229
本文介绍了Selenium - 脚本应该等到浏览器手动关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Java for selenium自动化
我有一个场景,我需要移动到黄瓜功能文件中的下一个场景,只有当我为当前场景手动关闭chrome浏览器。

I am using Java for selenium automation I have a scenario where I need to should move to next scenario in cucumber feature file only when I close the chrome browser manually for the current scenario.

请帮助我实现这个

推荐答案

死亡或无法到达例外..

You can try something like looping until you got browser died or not reachable exception..

 WebDriver driver = new FirefoxDriver();

    driver.get("http://www.google.com");

    Boolean check = false;

    while (!check) {

        try {
            driver.getTitle();
            Thread.sleep(200);
        } catch (Exception e) {
            //you can verify correct exception here ie not reachable, dead etc..
            check = true;
        }

    }

    System.out.println("after browser close");
    //continue your code here

这篇关于Selenium - 脚本应该等到浏览器手动关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆