【发布时间】:2017-10-20 11:58:40
【问题描述】:
我想无头运行 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 应该无头运行,但它会在普通窗口中打开。
更新 我将 Firefox 更新为 56.0.1
现在我得到一个不同的错误:
“OpenQA.Selenium.WebDriverException”类型的未处理异常 发生在 WebDriver.dll 中
附加信息:预期的浏览器二进制位置,但无法 在默认位置查找二进制文件,没有 'moz:firefoxOptions.binary' 提供了功能,并且在命令行上没有设置二进制标志
【问题讨论】:
标签: c# selenium firefox headless headless-browser