Selenium无法创建chromeDriver会话

Selenium无法创建chromeDriver会话,第1张

Selenium无法创建chromeDriver会话
Starting ChromeDriver 96.0.4664.45 (76e4c1bb2ab4671b8beba3444e61c0f17584b2fc-refs/branch-heads/4664@{#947}) on port 46287
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: Unable to create new remote session. desired capabilities = Capabilities [{browserName=chrome, chromeOptions=org.openqa.selenium.chrome.ChromeOptions@1b550c0, version=, platform=ANY}], required capabilities = Capabilities [{}]
Build info: version: '3.3.0', revision: 'b526bd5', time: '2017-03-07 11:21:31 -0800'
System info: host: '602-80', ip: '192.168.22.80', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_311'
Driver info: driver.version: ChromeDriver
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
	at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
	at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)
	at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131)
	at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:144)
	at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:178)
	at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:167)
	at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:124)
	at moocTest.TestMain.main(TestMain.java:12)

 其中下面的代码是chromeDriver的版本

Starting ChromeDriver 96.0.4664.45 (76e4c1bb2ab4671b8beba3444e61c0f17584b2fc-refs/branch-heads/4664@{#947}) on port 46287
only local connections are allowed.

表示当前的版本为96.0.4664.45。

而Java测试代码为

package moocTest;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class TestMain {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		WebDriver webDriver = new ChromeDriver();
		
		webDriver.get("http://www.xjtu.edu.cn");
		
		String title = webDriver.getTitle();
		System.out.println("打开网站的标题为:" + title);
		
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		WebElement okElement = webDriver.findElement(By.xpath("/html/body/div[4]/div/div[1]/ul/li[1]/a"));
		
		okElement.click();
		
//		try {
//			Thread.sleep(5000);
//		} catch (InterruptedException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		
//		webDriver.close();
	}

}

使用的selenium-standalone.jar

 版本对应的chromeDriver是ChromeDriver 2.36.540470,chrome是85.0.4183.83_chrome_installer_32。

上述问题在于selenium的版本与chromeDriver和chrome版本不兼容所致,需要确保两者一致。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5670891.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存