我想運行firefox無頭。Selenium C中的無頭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應該運行無頭,但它會在一個普通窗口中打開。
更新 我更新火狐56.0.1
現在,我得到一個不同的錯誤:
An unhandled exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll
Additional information: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
它顯示了一個例外,當我使用'--headless'。 **所有參數必須以兩個破折號(' - ')開頭;參數'-headless'沒有。** – Raven
我更新了Firefox的最新版本,我現在得到了一個不同的錯誤。請檢查我更新的問題。 – Raven
@Raven你正在使用哪個版本的'geckodriver'?我想你可能在64位系統上使用32位。嘗試x64版本:https://github.com/mozilla/geckodriver/releases – Equalsk