错误堆栈跟踪(从注释更新):
Starting ChromeDriver 2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067) on port 7778 Only local connections are allowed.
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: session not created exception from unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"961185F0AA38D24650EF6C797BC32535","isDefault":true,"type":"default"},"id":1,"name":"","origin":"://"}
(Session info: chrome=70.0.3538.102)
(Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.68 seconds Build info: version: '3.141.5', revision: 'd54ebd709a', time: '2018-11-06T11:58:41'
System info: host: 'LTAH024', ip: '192.168.131.142', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_60'
Driver info: driver.version: ChromeDriver
我写了一个简单的程序来启动chrome浏览器。请参见下面的代码。我已经在环境变量中设置了路径:
package automationFramework;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class ChromeBrowser {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver drive = new ChromeDriver();
drive.get("http://toolsqa.com/selenium-webdriver/running-tests-in-chrome-browser/");
System.out.println("Successfully open tools qa website in Chrome browser");
//Thread.sleep(5000); //To initiate thread , we need to add throws interrupt exception
//Close the driver
//driver.quit();
}
}
请调查一下并帮帮我。 Firefox的geckodriver
也在工作。
答案 0 :(得分:0)
Download chrome driver,将其保存在您的本地地址,并将路径放在System.setProperty
处,尝试以下代码,希望对您有所帮助。
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class ChromeBrowser {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "B:\\chromedriver.exe"); //put driver path here
WebDriver drive = new ChromeDriver();
drive.get("http://toolsqa.com/selenium-webdriver/running-tests-in- chrome-browser/");
System.out.println("Successfully open tools qa website in Chrome browser");
drive.quit();
}
}
答案 1 :(得分:0)
打开Chrome浏览器的三种方法:
第一个:使用system.setproperty
System.setProperty("webdriver.chrome.driver", "F:\\New folder\\chromedriver.exe");
Webdriver driver = new ChromeDriver();
第二个:使用Chrome选项:
//set path to chromedriver.exe
ChromeOptions options = new ChromeOptions();
options.setAcceptInsecureCerts(true);
options.setBinary(new File("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"));
options.addArguments("disable-infobars");
System.setProperty("webdriver.chrome.driver", "F:\\New folder\\chromedriver.exe");
driver = new ChromeDriver(options);
最后一个:如果您正在使用maven,请使用此
这将下载最新版本的chrome驱动程序并启动它。您可以在使用bonigarcia依赖项内使用WebDriverManager。在Bom.xml文件中添加bonigarcia依赖项,并通过WebdriverManager开始使用它
https://github.com/bonigarcia/webdrivermanager
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
最后Gecko驱动程序和Firefox的版本是什么?
答案 2 :(得分:0)
此错误消息...
Starting ChromeDriver 2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067) on port 7778 Only local connections are allowed.
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: session not created exception from unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"961185F0AA38D24650EF6C797BC32535","isDefault":true,"type":"default"},"id":1,"name":"","origin":"://"}
(Session info: chrome=70.0.3538.102)
(Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.68 seconds Build info: version: '3.141.5', revision: 'd54ebd709a', time: '2018-11-06T11:58:41'
System info: host: 'LTAH024', ip: '192.168.131.142', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_60'
Driver info: driver.version: ChromeDriver
...表示 ChromeDriver 无法启动/产生新的 WebBrowser ,即 Chrome浏览器会话。
您确实有3个问题,主要问题是所使用的二进制文件版本之间的不兼容性:
支持 Chrome v43-48
支持 Chrome v69-71
因此 JDK v8u60 , Selenium Client v3.141.5 , ChromeDriver v2.20 和之间存在明显的不匹配Chrome浏览器v70.0
使用 Selenium v3.x 客户端时,您需要从ChromeDriver - WebDriver for Chrome下载最新的 ChromeDriver ,并将其存储在系统中的任何位置并提供<通过 System.setProperty()
行的 ChromeDriver 的em>绝对路径,如下所示:
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
将 JDK 升级到最新级别JDK 8u191。
@Test
。driver.quit()
方法内调用tearDown(){}
,以优雅地关闭和销毁 WebDriver 和 Web Client 实例。