Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Selenium C中的无头Firefox#_C#_Selenium_Firefox_Headless_Headless Browser - Fatal编程技术网

C# Selenium C中的无头Firefox#

C# Selenium C中的无头Firefox#,c#,selenium,firefox,headless,headless-browser,C#,Selenium,Firefox,Headless,Headless Browser,我想无头运行firefox Firefox不隐藏浏览器窗口或在虚拟桌面中打开它,而是通过使用“-headless”标志支持无头模式 问题是我知道如何在chrome中实现,但在Firefox中却不知道 我的代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using S

我想无头运行firefox

Firefox不隐藏浏览器窗口或在虚拟桌面中打开它,而是通过使用“-headless”标志支持无头模式

问题是我知道如何在chrome中实现,但在Firefox中却不知道

我的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

namespace MyApp {
public partial class Form1: Form {
    public Form1() {
        InitializeComponent();
    }

    private void StartBtn_Click(object sender, EventArgs e) {

        IWebDriver driver;
        FirefoxOptions options = new FirefoxOptions();
        options.AddArguments("--headless");
        driver = new FirefoxDriver(options);
    }
}
}
我的WinForm应用程序只有一个名为StartBtn的按钮。 点击按钮Firefox应该运行headless,但它会在一个普通窗口中打开


更新 我将firefox更新为56.0.1

现在我得到一个不同的错误:

“OpenQA.Selenium.WebDriverException”类型的未处理异常 发生在WebDriver.dll中

其他信息:预期的浏览器二进制位置,但无法 要在默认位置查找二进制文件,请不要使用“moz:firefoxOptions.binary” 提供了功能,并且没有在命令行上设置二进制标志


Firefox中的Headless模式在Windows和Mac OS上的版本56支持。确保安装了正确的版本

使用Firefox v56.0.1、Selenium.WebDriver v3.6.0和geckodriver v0.19.0(x64),这对我来说是正确的

关于错误:

WebDriver.dll中发生“OpenQA.Selenium.WebDriverException”类型的未处理异常

确保您使用的是正确版本的
geckodriver
。我怀疑您正在使用
x32
构建在
x64
机器上,获取
x64
构建


当我使用
--headless
时,它显示一个异常。所有参数必须以两个破折号('--')开头;参数'-headless'没有。我将firefox更新为最新版本,现在我得到一个不同的错误。请检查我更新的问题。@Raven您使用的是哪个版本的
geckodriver
?我认为您可能在64位系统上使用32位。尝试x64版本:将32位geckodriver替换为64位geckodriver。非常感谢!