You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法设置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.ChromeOptions
  • org.openqa.selenium.remote.CapabilityType
  • org.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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 06:09:04