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

Eclipse中使用Selenium WebDriver运行Java代码自动化浏览器时报错

解决方案

你遇到的是Chrome渲染进程超时错误,可按以下步骤排查修复:

  • 修复代码中Windows路径转义问题(本次ChromeDriver启动成功,但该写法存在长期隐患),将文件路径的单斜杠替换为双斜杠或者正斜杠
  • 添加Chrome启动参数禁用GPU硬件加速,该配置是解决Windows平台Chrome渲染超时的最常用方案
  • 若存在谷歌站点访问限制,可先替换测试地址为国内可正常访问的站点,验证是否为网络问题导致的超时
  • 可按需调整页面加载策略和超时时间,降低超时触发概率

修复后完整代码示例

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.PageLoadStrategy;
import java.time.Duration;

public class AyeshaDemo1 {

    public static void main(String[] args) {
        // 修复路径转义问题
        System.setProperty("webdriver.chrome.driver", "C:\\Course\\chromedriver.exe");
        // 初始化Chrome配置项
        ChromeOptions options = new ChromeOptions();
        // 禁用GPU加速解决渲染超时问题
        options.addArguments("--disable-gpu");
        // 调整页面加载策略为仅等待DOM加载完成,无需等待图片、样式等静态资源加载
        options.setPageLoadStrategy(PageLoadStrategy.EAGER);
        
        WebDriver driver = new ChromeDriver(options);
        // 调整页面加载超时时间为10分钟,可根据自身需求修改时长
        driver.manage().timeouts().pageLoadTimeout(Duration.ofMinutes(10));
        // 可先替换为百度地址测试是否为谷歌访问限制导致的超时
        driver.get("https://www.baidu.com");       
    }
}

内容的提问来源于stack exchange,提问作者Aishu 418

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.04 16:09:03