Selenium java+selenium+chrome,无法取消通知弹窗

Leslie · 2018年11月22日 · 最后由 Leslie 回复于 2018年11月22日 · 1428 次阅读

网上查询需要 ChromeOptions,但是按照那种写法依旧会出现弹框

具体代码为:

public class Login {
    public static void main(String[] args) {
        String url = "https://deal-xxxx";
        WebDriver driver = new ChromeDriver();
        Map<String, Object> prefs = new HashMap<String, Object>();

        prefs.put("profile.default_content_setting_values.notifications", 2);
        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("prefs", prefs);


        driver.manage().timeouts().implicitlyWait(2000, TimeUnit.SECONDS);
//      driver.manage().window().maximize();
        driver.get(url);

        driver.findElement(By.className("account")).sendKeys("xxxxx");
        driver.findElement(By.className("password")).sendKeys("xxxx");
        driver.findElement(By.className("content")).click();
    }
}
共收到 4 条回复 时间 点赞

你的 options 根本都没用,options 需要在初始化 Driver 的时候传进去。😓

WebDriver driver = new ChromeDriver(options);

arrow 回复

哈哈哈,好滴,谢谢谢谢🙏

槽神 回复

好滴好滴,灰常感谢🙏

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册