我只是通过输入页面的URL来调用Chrome浏览器。它打开一个浏览器并立即关闭。但是,我已经在POM.xml文件上添加了依赖项。
你可以在下面找到代码,
package com.Rezaid.webdriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class OpenBrowser {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C://Users//BiTS//Downloads//chromedrivers//chromedriver.exe");
ChromeDriver driver = new ChromeDriver();
driver.get("https://www.google.com");
System.out.println(driver.getCurrentUrl());
}
我要你告诉我解决方案,这样我才能运行代码。
错误如下所示,
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052}) on port 10550
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: session not created: This version of ChromeDriver only supports Chrome version 114
Current browser version is 116.0.5845.111 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe
3条答案
按热度按时间lztngnrs1#
不确定您使用的是哪个版本的selenium,因为您系统中的Chrome版本是
116
,您需要将selenium升级到最新的4.11.0
。查看以下内容:一旦你升级了,设置
System.setProperty
路径不再是强制性的,你可以跳过这一行。Selenium将在内部为您下载和管理驱动程序。代码可以简化如下:请参考这些答案以了解类似问题:
2exbekwf2#
您可以使用
WebDriverManager.chromedriver().setup();
启动Chrome浏览器,并在pom文件中使用以下内容lbsnaicq3#
你应该更新selenium版本到4.11