org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created:

huangapple go评论51阅读模式
英文:

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created:

问题

"org.openqa.selenium.SessionNotCreatedException: 
无法启动新会话。响应代码为500。
消息:未创建会话:此版本的ChromeDriver仅支持Chrome版本91"

代码如下:

        ChromeOptions options = new ChromeOptions();
    	options.setExperimentalOption("excludeSwitches", new String[] { "enable-automation" });
    	WebDriver driver = new ChromeDriver(options);
    	driver.manage().window().maximize();
    	driver.navigate().to("https://www.google.com/");

注意:如果我使用最新版本的System.setProperty,它可以工作。

英文:

I'm trying to invoke the chrome browser using testng, maven but code is giving below error.

"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 91"

Code as follows:

    ChromeOptions options = new ChromeOptions();
	options.setExperimentalOption("excludeSwitches", new String[] { "enable-automation" });
	WebDriver driver = new ChromeDriver(options);
	driver.manage().window().maximize();
	driver.navigate().to("https://www.google.com/");`

I'm expecting to open the browser without using

System.setProperty("webdriver.chrome.driver", "C:\\Seleniun\\sws\\chromedriver.exe"); 

Because I'm using all the below maven dependencies

`<dependency>
			<groupId>org.seleniumhq.selenium</groupId>
			<artifactId>selenium-java</artifactId>
			<version>4.9.1</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.testng/testng -->
		<dependency>
			<groupId>org.testng</groupId>
			<artifactId>testng</artifactId>
			<version>7.7.1</version>
			<scope>test</scope>
		</dependency>
		<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
		<dependency>
			<groupId>io.github.bonigarcia</groupId>
			<artifactId>webdrivermanager</artifactId>
			<version>5.3.3</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
		<dependency>
			<groupId>org.seleniumhq.selenium</groupId>
			<artifactId>selenium-chrome-driver</artifactId>
			<version>4.9.1</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
		<dependency>`

Note: If I use the System.setProperty with latest version it is working.

答案1

得分: 0

以下是翻译好的部分:

即使您使用了上述依赖项,也不会起作用,因为下面是Selenium知道Chromedriver二进制文件的位置的方式,它用于在Chrome中执行自动化。

System.setProperty("webdriver.chrome.driver", "");

由于您使用了Webdriver Manager,您可以在驱动程序初始化之前添加此行,它将下载驱动程序二进制文件并在内部调用System.setProperty来设置Chrome驱动程序路径。Webdriver Manager将自动下载与您的Chrome浏览器版本匹配的chromedriver。

完整代码:

WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", new String[] { "enable-automation" });
WebDriver driver = new ChromeDriver(options);
driver.manage().window().maximize();
driver.navigate().to("https://www.google.com/");
英文:

Even if you are using above dependencies it wont work because below is how selenium knows where the Chromedriver binary file is which it use for Automation execution in chrome

System.setProperty("webdriver.chrome.driver","")

Since you are using Webdriver Manager you can add this line before your driver initialisation which will downlaod the driver binary and Internally calls System.setProperty to set the chrome driver path
. Webdriver Manager will automatically download the chromedriver matching your chrome browser version

Complete code

WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", new String[] { "enable-automation" });
WebDriver driver = new ChromeDriver(options);
driver.manage().window().maximize();
driver.navigate().to("https://www.google.com/");`

huangapple
  • 本文由 发表于 2023年5月13日 21:23:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76242954.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定