出现未创建会话异常:无法使用Maven和Java17启动新会话

bd1hkmkf  于 2023-01-20  发布在  Maven
关注(0)|答案(1)|浏览(240)

我正面临着这样的错误:

org.openqa.selenium.SessionNotCreatedException: Could not start a new session

完整错误堆栈跟踪:

[main] INFO io.github.bonigarcia.wdm.WebDriverManager - Exporting webdriver.chrome.driver as C:\Users\ajays\.m2\repository\webdriver\chromedriver\win32\109.0.5414.74\chromedriver.exe
Starting ChromeDriver 109.0.5414.74 (e7c5703604daa9cc128ccf5a5d3e993513758913-refs/branch-heads/5414@{#1172}) on port 46129
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: crashed.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location C:\Users\ajays\AppData\Local\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.) 
Host info: host: 'LAPTOP-8VG52IH3', ip: '192.168.20.2'
Build info: version: '4.7.0', revision: '0a5b49d16f'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.5'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}}], desiredCapabilities=Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}}}]
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:148)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:106)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:541)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157)
    at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:101)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:81)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:49)
    at class1test.Demo1.main(Demo1.java:14)

Maven项目配置:

添加的依赖项:

这是我创建的Maven项目。它显示了什么无法启动新会话?

vyswwuz2

vyswwuz21#

可能Selenium仍然与java-17不兼容。
尝试将Java编译器的sourcetarget参数强制为 maven-compiler-plugin 内的 v1.8,如下所示:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>

下面是完整的<build>依赖关系:

<build>
    <pluginManagement>
      <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>3.0.0-M5</version>
          <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
 
  <dependencies>
    ...
    ...
  </dependencies>

相关问题