运行 selenium 代码时出现以下错误

问题描述 投票:0回答:1
    Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created: This version of ChromeDriver only supports Chrome version 122
Current browser version is 121.0.6167.161 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe 
Build info: version: '4.18.1', revision: 'b1d3319b48'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.2'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}}]}]
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:139)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:95)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:162)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:216)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:174)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:519)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:233)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:162)
    at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:114)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:89)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:84)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:52)
    at SeleniumIntro.main(SeleniumIntro.java:17)

下面是我的代码:

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
     import org.openqa.selenium.chrome.ChromeDriverService;

    public class SeleniumIntro {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        System.setProperty("webdriver.chrome.driver", "D:\\chromedriver-win64\\chromedriver.exe");
        
        WebDriver driver = new ChromeDriver();

        driver.get("https://google.com");
    }
}
java selenium-webdriver selenium-chromedriver
1个回答
0
投票

只需从代码中删除以下行即可,您不需要它。让 Selenium Manager 进行驱动程序管理。

System.setProperty("webdriver.chrome.driver", "D:\\chromedriver-win64\\chromedriver.exe");

要了解有关 Selenium Manager 的更多信息,请查看以下答案:

© www.soinside.com 2019 - 2024. All rights reserved.