Linux调用Selenium报session not created: Chrome failed to start: exited normally.的问题解决方式

确定了浏览器版本和chromedriver版本可以对应得上,但是每次调用对应的服务都会报该错误

问题在于启动Selenium需要桌面,然而你的Linux上没有桌面,所以报错,解决这个问题的方式是将Selenium设置为不使用浏览器启动,然而不使用浏览器启动存在对应的元素没加载的问题,解决该问题的方式是设置浏览器大小,我的是1366-768,使用了这个配置之后问题就解决了

配置代码如下

public class ChromeUtil {
    public static ChromeDriver getChromeDriver() {
        // 本地测试,本地需配置同版本的chromedriver和Chrome,测试时保持Chrome网页运行
        // chrome会自动更新,需注意保持版本不变
        // 快速入门教学:https://blog.csdn.net/chenjxj123/article/details/121802904
        System.setProperty("webdriver.chrome.driver", "/usr/local/chromeDriver/chromedriver");
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        options.addArguments("--headless");
        ChromeDriver driver = new ChromeDriver(options);
        driver.manage().window().setSize(new Dimension(1366,768));
        return driver;
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值