Chrome 111升级后Selenium WebDriver随机TimeoutException问题求助
Chrome 111 + Selenium 4.6.0 随机触发 TimeoutException 问题
Chrome升级至111版本后,必须添加--remote-allow-origins=*参数才能正常启动WebDriver,但后续执行findElement、sendKeys、switchTo等操作时,会随机出现TimeoutException异常,已在ChromeOptions中添加no-sandbox参数。
异常日志
org.openqa.selenium.TimeoutException: java.util.concurrent.TimeoutException Build info: version: '4.6.0', revision: '79f1c02ae20' System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '15.0.2' Driver info: org.openqa.selenium.chrome.ChromeDriver Command: [93f8e26807f72a1db301042970c404c3, clickElement {id=99af3643-8e51-46fd-849a-a6968fb6916a}] Capabilities {acceptInsecureCerts: true, browserName: chrome, browserVersion: 111.0.5563.65, chrome: {chromedriverVersion: 111.0.5563.64 (c710e93d5b63..., userDataDir: C:\Users\kalkidna\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:49445}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: WINDOWS, proxy: Proxy(), se:cdp: ws://localhost:49445/devtoo..., se:cdpVersion: 111.0.5563.65, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true} Element: [[ChromeDriver: chrome on WINDOWS (93f8e26807f72a1db301042970c404c3)] -> id: submitbutton] Session ID: 93f8e26807f72a1db301042970c404c3 at org.openqa.selenium.remote.http.netty.NettyHttpHandler.makeCall(NettyHttpHandler.java:65) at org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42) at org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:56) at org.openqa.selenium.remote.http.netty.NettyHttpHandler.execute(NettyHttpHandler.java:49) at org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42) at org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:56) at org.openqa.selenium.remote.http.netty.NettyClient.execute(NettyClient.java:99) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:181) at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:541) at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:257) at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:78) at com.classes.SCLFiles.SCLFileLoading.sclFileLoad(SCLFileLoading.java:722) at com.classes.SCLFiles.SCLFileLoading.uploadFileWithGooseAndSampledValues(SCLFileLoading.java:1160) at com.testcases.SCLFiles.SCLFileLoadingTest.fileUploadWithGooseAndSVMessagesTest(SCLFileLoadingTest.java:369) at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) Caused by: java.util.concurrent.TimeoutException at java.base/java.util.concurrent.CompletableFuture.timedGet(CompletableFuture.java:1950) at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2085) at org.asynchttpclient.netty.NettyResponseFuture.get(NettyResponseFuture.java:206) at org.openqa.selenium.remote.http.netty.NettyHttpHandler.makeCall(NettyHttpHandler.java:59) ... 43 more
使用的Maven依赖
<dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.6.0</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-http-jdk-client</artifactId> <version>4.6.0</version> </dependency> <dependency> <groupId>com.googlecode.json-simple</groupId> <artifactId>json-simple</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.7.30</version> </dependency> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.3.0</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.aventstack</groupId> <artifactId>extentreports-testng-adapter</artifactId> <version>1.2.2</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.6</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-compress</artifactId> <version>1.18</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>4.1.0</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.1.0</version> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>31.0.1-jre</version> </dependency> <!-- https://mvnrepository.com/artifact/javax.mail/javax.mail-api --> <dependency> <groupId>com.sun.mail</groupId> <artifactId>javax.mail</artifactId> <version>1.6.0</version> </dependency> <!-- https://mvnrepository.com/artifact/javax.activation/activation --> <dependency> <groupId>javax.activation</groupId> <artifactId>activation</artifactId> <version>1.1.1</version> </dependency> <!-- https://mvnrepository.com/artifact/com.jcraft/jsch --> <dependency> <groupId>com.jcraft</groupId> <artifactId>jsch</artifactId> <version>0.1.55</version> </dependency> <dependency> <groupId>com.google.api-client</groupId> <artifactId>google-api-client-appengine</artifactId> <version>1.23.0</version> <exclusions> <exclusion> <groupId>com.google.guava</groupId> <artifactId>guava-jdk5</artifactId> </exclusion> </exclusions> </dependency> </dependencies>
解决建议
- 升级Selenium版本:Selenium 4.6.0与Chrome 111的兼容性存在缺陷,升级到4.8.0及以上版本可修复多数版本匹配问题。
- 统一HTTP客户端:当前依赖同时引入Netty和JDK HTTP客户端,移除
selenium-http-jdk-client依赖,强制使用单一客户端,避免冲突导致的超时。 - 优化等待策略:针对易超时操作设置显式等待,确保元素加载完成后再执行操作:
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); wait.until(ExpectedConditions.elementToBeClickable(By.id("submitbutton"))).click(); - 添加额外Chrome启动参数:
--disable-dev-shm-usage:缓解资源限制问题--disable-gpu:禁用GPU加速,避免渲染异常--start-maximized:最大化窗口,避免元素因尺寸问题不可交互
- 重新校验ChromeDriver:确保ChromeDriver与Chrome版本完全匹配,重新下载同版本驱动文件,排除文件损坏问题。
内容的提问来源于stack exchange,提问作者saab
相关产品推荐
相关产品推荐

