无法设置ChromeOptions capability,需添加哪些Maven依赖及导入对应库?
Selenium ChromeOptions告警行为配置解决方案
1. pom.xml 所需Maven依赖
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.10.0</version> <!-- 可替换为对应业务兼容的稳定版本 --> </dependency>
如果使用Selenium 3.x旧版本,可将版本号替换为3.141.59即可兼容对应配置语法。
2. 需导入的类库
org.openqa.selenium.chrome.ChromeOptionsorg.openqa.selenium.remote.CapabilityTypeorg.openqa.selenium.UnexpectedAlertBehaviour
3. 完整可用配置示例
ChromeOptions opts = new ChromeOptions(); // 配置自动忽略未处理的告警弹窗,避免抛出对应异常 opts.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
配置生效后,遇到如下未处理告警弹窗时会自动跳过,不会抛出异常:
org.openqa.selenium.UnhandledAlertException: unexpected alert open: {Alert text : abuse limit triggered}
内容的提问来源于stack exchange,提问作者Prophet
相关产品推荐
相关产品推荐

