【问题标题】:Unable to find a matching set of capabilities with selenium 3.8.1 and gecko driver 0.19.0无法找到与 selenium 3.8.1 和 gecko 驱动程序 0.19.0 匹配的一组功能
【发布时间】:2018-06-14 21:06:28
【问题描述】:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Webdriver {

    public static void main(String[] args) throws InterruptedException {
        // TODO Auto-generated method stub


        System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        //System.setProperty("webdriver.chrome.driver","C:\\Selenium\\chromedriver.exe");
        //WebDriver driver = new ChromeDriver();

        driver.get("https://maps.mapmyindia.com");

        Thread.sleep(2000);
        driver.findElement(By.id("auto")).sendKeys("TCS");

        Thread.sleep(2000);
        driver.findElement(By.id("auto_geo")).click();

当我在 eclipse luna 上运行此代码时出现错误:线程“主”org.openqa.selenium.SessionNotCreatedException 中的异常:无法找到一组匹配的功能

【问题讨论】:

  • 你使用的是哪个firefox版本

标签: selenium firefox exception webdriver


【解决方案1】:
new FirefoxDriver(DesiredCapabilities caps); 

已弃用,请使用

FirefoxOptions options = new FirefoxOptions();
options.setCapability("marionette", false);
WebDriver webDriver = new FirefoxDriver(options);

你很高兴

【讨论】:

    【解决方案2】:

    另一个可能的原因是 Firefox 版本过时。

    我升级了版本,它工作正常!

    我可以打开浏览器只设置options.setCapability("marionette", true);,然后在打开的窗口中我通过“关于Firefox”对话框升级。然后你必须删除关于marionette的行。

    可能我只使用marionette,而我们正在尝试将它与geckodriver 一起使用,它具有不同的协议。比我知道的任何人都可以确认或否认!

    【讨论】:

      【解决方案3】:

      SessionNotCreatedException

      SessionNotCreatedException 扩展了 WebDriverException 并且是 RuntimeException,表示无法创建会话。

      可能的原因:

      未创建新会话的可能原因如下:

      • JDKSeleniumWebDriverWeb Browser 版本之间的兼容性问题.
      • 前一个会话尚未发布的新会话通过GeckoDriverMarionette 访问相同的端口号。
      • 无法访问CPU
      • 缺少Physical Memory
      • 缺少Swap Memory
      • 缺少Disc Cache
      • 缺少Network Bandwidth
      • 系统中存在OS chores

      代码块:

      我在您的代码块中没有看到任何编码问题。

      解决办法:

      简单的解决方案如下:

      • 始终使用最新发布的 JDK (Java SE 9.0.1)、Selenium-Java 客户端 (v3.8.1)、WebDriver 变体 (GeckoDriver v0.19.1) 和 Web 浏览器 (Firefox Quantum Browser)。
      • 如果 Web 浏览器的基本版本太旧,请考虑通过 Revo Uninstaller 卸载浏览器并安装最新发布的 Firefox 浏览器 GA 版本。
      • 始终在 tearDown() 方法中使用 quit(),以便正确销毁 webdriver 和 webclient。
      • 在执行测试套件之前和之后从 IDE 中清理项目工作区。
      • 在执行测试之前和之后清除浏览器缓存。
      • 定期使用 CCleaner 工具清除操作系统的琐事。
      • 执行您的测试。

      【讨论】:

        【解决方案4】:

        您应该为 Firefox 添加功能。请修改您的代码如下

         System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");
        
         DesiredCapabilities capabilities = new DesiredCapabilities();
        
         capabilities = DesiredCapabilities.firefox();
         capabilities.setBrowserName("firefox");
         capabilities.setVersion("your firefox version");
         capabilities.setPlatform(Platform.WINDOWS);
         capabilities.setCapability("marionette", false);
        
         WebDriver driver = new FirefoxDriver(capabilities);
        
         driver.get("https://maps.mapmyindia.com");
        

        如果您的窗口是windows_nt,则输入windows_nt 而不是windows

        【讨论】:

        • 感谢您的建议,但我通过将我的 java 版本调整为 1.8.1 解决了这个问题,再次感谢您的支持。
        • 它只是打开 Firefox(48.0 版),但没有导航到该站点
        • 请将您的 Firefox 更新到最新版本。然后就可以正常运行了
        • 现在平台名称错误类型错误:给定平台名称 [object String] "windows",但当前平台是 [object String] "windows_nt",我将平台名称更改为 windows_nt 但它不起作用.
        • 设置 FirefoxOptions 也成功了:FirefoxOptions firefoxOptions; firefoxOptions = new FirefoxOptions(); firefoxOptions.setCapability("木偶", false);
        猜你喜欢
        • 2017-11-19
        • 2018-08-27
        • 2018-07-30
        • 2019-05-25
        • 2019-01-30
        • 2017-11-30
        相关资源
        最近更新 更多