0

下面的代码似乎没有更新我的 chromedriver:


import io.github.bonigarcia.wdm.WebDriverManager;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import testone2.firstTest;

import java.io.*;

public class testLogin {

    protected WebDriver driver;
    private int seconds;

    public testLogin() {
        super();
    }

    @BeforeTest
    public void beforeTest() {
        //Download the web driver executable
        String chromeVersion = null;
        try {
            FileReader reader = new FileReader("chromeVersion.txt");
            BufferedReader br = new BufferedReader(reader);

            String line;

            while ((line = br.readLine()) != null) {
                chromeVersion = line.trim();
            }
            reader.close();
        } catch (IOException e) {
            Throwable ioException = new Throwable();
            ioException.printStackTrace();
        }

        WebDriverManager.chromedriver().version(chromeVersion).setup();
        boolean oldVersion = false;
        try {
            driver = new ChromeDriver();
        } catch (Exception e) {
            oldVersion = false;
            String err = e.getMessage();
            chromeVersion = err.split("version is")[1].split("with binary path")[0].trim();
            try {
                FileWriter writer = new FileWriter("chromeVersion.txt", true);
                writer.write(chromeVersion);
                writer.close();
            } catch (IOException er) {
            }
        }


        if (!oldVersion) {
            WebDriverManager.chromedriver().version(chromeVersion).setup();
            driver = new ChromeDriver();
        }

    }


    public void sleep(int seconds) {
        try {
            Thread.sleep(seconds * 1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}

Chrome 版本为 88.0.4324.182(官方构建)(64 位),WebDriverManager 依赖项为 4.2.2

这在控制台中返回: io.github.bonigarcia.wdm.WebDriverManagerException: io.github.bonigarcia.wdm.WebDriverManagerException: chromedriver 88.0.4324.150 for WIN64 not found in https://chromedriver.storage.googleapis.com/

谁能指出它读取chromedriver版本的代码是否有问题?这里有什么问题?谢谢

4

1 回答 1

0

通过将 chromeversion.txt 设置为 88.0.4324.96 解决

于 2021-02-19T19:51:21.727 回答