selenium 启动chrome时导入配置文件

本文介绍如何使用Chromedriver启动Chrome浏览器时设置特定配置文件,以实现从上次位置继续的功能。通过设定非默认配置文件并调整浏览器偏好设置,可以确保每次打开浏览器时都能恢复到之前的状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

chromedriver, how to use predefind settings

 Each time chromedriver opens a browser, it creates new profile. The profile overwrites all the chrome settings. "Continue where you left off" option is part of the profile.

private static WebDriver startChrome() {
    ChromeOptions options = new ChromeOptions();
    options.addArguments("user-data-dir=c:\\temp\\chromeProf"); // Set non-default profile
    Map<String, Object> prefs = new HashMap<>();
    prefs.put("session.restore_on_startup", 1); // Edit profile preferences to be "Continue where you left off"
    options.setExperimentalOption("prefs", prefs); // Set preferences to ChromeOptions
    WebDriver driver = new ChromeDriver(options); // Start driver with those options
    driver.manage().window().maximize();
    return driver;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值