QA新手用Edge 109做Selenium自动化时遇连接关闭等错误求助
问题排查与解决
一、SLF4J 警告问题
SLF4J提示找不到org.slf4j.impl.StaticLoggerBinder,是因为仅引入了SLF4J API,未添加具体的日志实现依赖。在Maven项目的pom.xml中添加任意一种SLF4J绑定依赖即可消除警告:
方案1:添加 slf4j-simple 依赖
<dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.7.36</version> <!-- 版本可与项目中SLF4J API版本保持一致 --> <scope>runtime</scope> </dependency>
方案2:添加 logback-classic 依赖(更常用的日志实现)
<dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.11</version> </dependency>
二、WebDriverException: net::ERR_CONNECTION_CLOSED 错误
这个错误主要由版本不匹配、配置错误或驱动路径问题导致,按以下步骤排查:
确保EdgeDriver与Edge浏览器版本严格匹配
你的Edge浏览器版本是109.0.1518.61,必须下载对应版本的EdgeDriver。下载后可将驱动所在目录添加到系统环境变量PATH,或通过代码指定路径。修正EdgeOptions的参数配置
代码中options.addArguments("edge.switches","--disable-extensions");写法错误,新版EdgeDriver无需edge.switches前缀,直接添加参数即可:import org.openqa.selenium.WebDriver; import org.openqa.selenium.edge.EdgeDriver; import org.openqa.selenium.edge.EdgeOptions; public class BrowserTest { public static void main(String[] args) { EdgeOptions options = new EdgeOptions(); options.addArguments("--disable-extensions"); // 修正参数写法 WebDriver driver = new EdgeDriver(options); // 变量名改为小写,符合Java编码规范 driver.get("https://seleniumhq.org/"); } }指定EdgeDriver路径(可选,若驱动不在PATH中)
在初始化EdgeDriver前添加系统属性配置,替换为你的驱动实际路径:System.setProperty("webdriver.edge.driver", "D:\\path\\to\\msedgedriver.exe"); EdgeOptions options = new EdgeOptions(); options.addArguments("--disable-extensions"); WebDriver driver = new EdgeDriver(options);检查Selenium依赖版本
确保Maven中selenium-java或selenium-edge-driver的版本与EdgeDriver兼容,适配Edge 109的Selenium版本推荐4.7.2及以上:<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.7.2</version> </dependency>
内容的提问来源于stack exchange,提问作者An Nihal
相关产品推荐
相关产品推荐

