Selenium之cannot find Chrome binary错误

cannot find Chrome binary 错误展示
cannot find Chrome binary
修改之后:

我需要告诉它我的 Chrome 所在位置(不告诉的话它会以为我的 Chrome 默认在 C盘)

下图创建驱动对象来打开浏览器,运行错误:还是未找到 Chrome

修改之后:

public class firstautotest {
    //创建一个驱动对象来打开浏览器
     ChromeDriver driver;
//    ChromeOptions options = new ChromeOptions();
//    options.addArguments("--remote-allow-origins=*");
//    options.setBinary("D:\\SoftWare\\Google\\Chrome\\Application\\chrome.exe");
//    ChromeDriver driver = new ChromeDriver();
    public void start_test() throws InterruptedException {
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        options.setBinary("D:\\SoftWare\\Google\\Chrome\\Application\\chrome.exe");
        driver = new ChromeDriver (options);
        driver.get("https://www.baidu.com");
    }

正确

我的 Chrome 所在位置
当我们需要创建驱动对象打开浏览器,这个时候就需要需要告诉 Chrome 的位置(路径),也就是我们要创建几次驱动对象,就要多写几次 Chrome路径 的代码,只需要创建一次的话其实就多写两行代码

options.setBinary("D:\\SoftWare\\Google\\Chrome\\Application\\chrome.exe");
driver = new ChromeDriver (options);

温馨提示:还是默认C盘不会出问题啊!!!
流泪

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Spring用于定义Bean对象生命周期方法的注解是@PostConstruct和@PreDestroy。 1. @PostConstruct:该注解用于标注一个初始化方法,该方法将在Bean对象创建后,且属性注入完成后执行。它可以替代传统的init-method属性。 2. @PreDestroy:该注解用于标注一个销毁方法,该方法将在Bean对象销毁前执行。它可以替代传统的destroy-method属性。 需要注意的是,@PostConstruct和@PreDestroy注解必须要与实现了InitializingBean和DisposableBean接口的方法配合使用,才能够实现Bean对象的完整的生命周期管理。例如: ``` @Service public class UserServiceImpl implements UserService, InitializingBean, DisposableBean { @Override public void afterPropertiesSet() throws Exception { // 在Bean对象创建后,且属性注入完成后执行 } @Override public void destroy() throws Exception { // 在Bean对象销毁前执行 } @PostConstruct public void init() { // 在Bean对象创建后,且属性注入完成后执行 } @PreDestroy public void cleanup() { // 在Bean对象销毁前执行 } // ... } ``` 上述代码中,实现了InitializingBean和DisposableBean接口的方法将会在Bean对象的创建和销毁阶段执行,@PostConstruct和@PreDestroy注解标注的方法也将会在创建和销毁阶段执行。需要注意的是,@PostConstruct和@PreDestroy注解标注的方法可以与实现了InitializingBean和DisposableBean接口的方法同时存在,Spring将会依次调用它们。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值