java - SeleniumError : org. openqa.selenium.SessionNotCreatedException

标签 java selenium selenium-webdriver

在执行 java 代码期间执行 driver.close();driver.quit(); 时,会引发以下错误:

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Tried to run command without establishing a connection Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:26.402Z' System info: host: 'ADMIN-PC', ip: '192.168.1.6', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_151' Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{moz:profile=C:\Users\admin\AppData\Local\Temp\rust_mozprofile.ENTBvl2aDbSs, rotatable=false, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, moz:headless=false, platform=XP, specificationLevel=0, moz:accessibilityChecks=false, acceptInsecureCerts=true, browserVersion=56.0.2, platformVersion=10.0, moz:processID=5004, browserName=firefox, javascriptEnabled=true, platformName=XP}] Session ID: 82e7dabd-c178-4d90-a3f8-84dc3f6ff14f at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:185) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:120) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:643) at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:482) at yahoo.main(yahoo.java:34)

分享抛出上述异常的代码:

//package basicSeleniumScripts;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class yahoo {

public static void main(String[] args) {
    String Firefoxdriverpath = "C:\\Marionette\\geckodriver_1.exe";
    WebDriver driver;

    System.setProperty("webdriver.gecko.driver",Firefoxdriverpath);
    //create a new instance of Firefox driver
    driver = new FirefoxDriver();
    //Open the page we want to open
    driver.get("http://www.yahoo.com");
    //Defining expected title 
    String expectedTitle = "Yahoo";
    //Getting the actual title
    String actualTitle = null;
    actualTitle = driver.getTitle();

    //Validating the TestCase

    if (actualTitle.contentEquals(expectedTitle))
    {
        System.out.println("Test Passed");
    }

    else 
        {
        System.out.println("Test Failed!!!");
        }
    driver.close();
    driver.quit();
}


}

最佳答案

将 gecko 驱动程序版本更新到 v0.19.0,因为您使用的是 3.6.0 jars of selenium。

也仅使用退出方法

关于java - SeleniumError : org. openqa.selenium.SessionNotCreatedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47185007/

相关文章:

Maven+Selenium+Jetty - Jetty 关闭时出现 ClassNotFoundException

java - Selenium WebDriver 拖放到滚动条

java - 添加 pom.xml 后无法使用 IE 和 Chrome WebDrivers

java - 队列上 IBM MQ 的 IsOpen 和 OpenStatus 属性有何区别?

java - Optaplanner 项目的非法参数异常,解算器配置在类加载器中不作为类路径资源存在

java - 最小化 Java "warm-up"时间的技术或实用程序?

java - 让 Selenium 等待文件下载完成

Java 没有显示我正在寻找的输出(初学者)

python - 无法捕获异常

java - 读取 Excel 工作表数据和打印值时出现 NoClassDefFoundError