Selenium使用过程中出现Exception in thread “main“ org.openqa.selenium.SessionNotCreatedException: Could not
问题描述
在启动Selenium过程中出现了一大串报错,检查了chrome的版本也对的上,和Selenium的版本也对的上,我的代码如下
import org.openqa.selenium.WebDriver;import org.openqa.selenium.chrome.ChromeDriver;public class Main { public static void main(String[] args) { // 设置chromedriver.exe的路径 System.setProperty(\"webdriver.chrome.driver\", \"C:\\\\Program Files\\\\Google\\\\Chrome\\\\Application\"); WebDriver chromeDriver = new ChromeDriver(); String url = \"https://www.baidu.com\"; chromeDriver.get(url); try { Thread.sleep(30000); } catch (InterruptedException e) { e.printStackTrace(); } chromeDriver.quit(); }}
得到报错Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
解决方案
其实还是因为找不到chromedriver,我把他添加到了环境变量,但是还是不行,既然一直找不到,那就直接在程序里面给他写上
System.setProperty(\"webdriver.chrome.driver\", \"C:\\\\Program Files\\\\Google\\\\Chrome\\\\Application\\\\chromedriver.exe\");
这样就可以了。