Firefox特有の機能

これらは、Mozilla Firefoxブラウザに特有の機能と機能です。

Selenium 4 には Firefox 78 以降が必要です。 常に最新バージョンの geckodriver を使用することをお勧めします。

オプション

全ブラウザに共通のCapabilityについては、オプションページで説明しています。

Firefox に固有のCapabilityは、Mozilla のページの firefoxOptions にあります。

基本的な定義済みのオプションを使用して Firefox セッションを開始すると、以下のようになります。

        Assertions.assertEquals("Content injected by webextensions-selenium-example", injected.getText());
    }
    driver = webdriver.Firefox(options=options)
            driver.InstallAddOnFromFile(Path.GetFullPath(extensionFilePath));
    @driver = Selenium::WebDriver.for :firefox, options: options
  end
      let options = new firefox.Options();
      driver = await env.builder()
        .setFirefoxOptions(options)
        .build();

さまざまなCapabilityを備えた一般的な使用例をいくつか示します。

引数

args パラメータは、ブラウザの起動時に使用するコマンドラインスイッチのリストです。 一般的に使用される引数には、 -headless"-profile""/path/to/profile" が含まれます。

オプションに引数を追加します。

        driver.uninstallExtension(id);
         public void UnInstallAddon()
    driver.get 'https://www.selenium.dev/selenium/web/blank.html'
    let driver = await env.builder()

指定したロケーションでブラウザを起動する

binary パラメーターは、使用するブラウザーの別のロケーションのパスを取ります。 たとえば、このパラメーターを使用すると、geckodriver を使用して、製品版とFirefox Nightlyの両方がコンピューターに存在する場合、 製品版の代わりに Firefox Nightly を駆動できます 。

オプションにブラウザーのロケーションを追加します。

        driver.installExtension(path, true);
            Assert.AreEqual(driver.FindElements(By.Id("webextensions-selenium-example")).Count, 0);
    driver.uninstall_addon(extension_id)

プロファイル

Firefoxプロファイルを操作するにはいくつかの方法があります。

var options = new FirefoxOptions();
var profile = new FirefoxProfile();
options.Profile = profile;
var driver = new RemoteWebDriver(options);
  
const { Builder } = require("selenium-webdriver");
const firefox = require('selenium-webdriver/firefox');

const options = new firefox.Options();
let profile = '/path to custom profile';
options.setProfile(profile);
const driver = new Builder()
    .forBrowser('firefox')
    .setFirefoxOptions(options)
    .build();
  
val options = FirefoxOptions()
options.profile = FirefoxProfile()
driver = RemoteWebDriver(options)
  

Note: Whether you create an empty FirefoxProfile or point it to the directory of your own profile, Selenium will create a temporary directory to store either the data of the new profile or a copy of your existing one. Every time you run your program, a different temporary directory will be created. These directories are not cleaned up explicitly by Selenium, they should eventually get removed by the operating system. However, if you want to remove the copy manually (e.g. if your profile is large in size), the path of the copy is exposed by the FirefoxProfile object. Check the language specific implementation to see how to retrieve that location.

If you want to use an existing Firefox profile, you can pass in the path to that profile. Please refer to the official Firefox documentation for instructions on how to find the directory of your profile.

サービス

すべてのブラウザに共通するサービス設定は、Service pageに記載されています。

ログ出力

ドライバーログを取得することは、さまざまな問題のデバッグに役立ちます。サービスクラスを使用すると、ログの保存先を指定できます。ログ出力は、ユーザーがどこかに指定しない限り無視されます。

ファイル出力

特定のファイルにログ出力を保存するには:

        System.setOut(new PrintStream(getLogLocation()));

: Java では、システムプロパティによってファイル出力を設定することもできます。
プロパティキー:GeckoDriverService.GECKO_DRIVER_LOG_PROPERTY
プロパティ値: ログファイルへのパスを表す文字列

Selenium v4.10

        @driver = Selenium::WebDriver.for :firefox, service: service

コンソール出力

ログ出力をコンソールに表示するには、以下のようにします:

Selenium v4.10

        System.setProperty(GeckoDriverService.GECKO_DRIVER_LOG_PROPERTY,
                getLogLocation().getAbsolutePath());

注意: Javaは、システムプロパティを使用してコンソール出力を設定することもできます;
プロパティキー: GeckoDriverService.GECKO_DRIVER_LOG_PROPERTY
プロパティ値: DriverService.LOG_STDOUT または DriverService.LOG_STDERR

Selenium v4.10

      @driver = Selenium::WebDriver.for :firefox, service: service

ログレベル

利用可能なログレベルは7つあります: fatal, error, warn, info, config, debug, trace。 ロギングが指定されている場合、デフォルトのレベルは infoになります。

-v iは -log debug と同等であり、-vvlog traceと同等です。 したがって、この例は一般的にログレベルを設定するためのものです:

Selenium v4.10

    public void stopsTruncatingLogs() throws IOException {
        System.setProperty(GeckoDriverService.GECKO_DRIVER_LOG_PROPERTY,

注意: Javaは、システムプロパティによってログレベルの設定も可能です:
プロパティキー: GeckoDriverService.GECKO_DRIVER_LOG_LEVEL_PROPERTY
プロパティ値:FirefoxDriverLogLevel列挙型の文字列表現

トランケートログ

ドライバーは、大きなバイナリの文字列表現を含む、送信されたすべてのものをログに記録します。そのため、Firefoxではデフォルトで行が切り捨てられます。切り捨てを無効にするには:

Selenium v4.10

    @Test
    public void setProfileLocation() throws IOException {

注意: Javaでは、システムプロパティによってログレベルを設定することもできます。
プロパティキー: GeckoDriverService.GECKO_DRIVER_LOG_NO_TRUNCATE
プロパティ値: "true" または "false"

プロファイルルート

プロファイルのデフォルトディレクトリは、システムの一時ディレクトリです。そのディレクトリにアクセスできない場合や、特定の場所にプロファイルを作成したい場合は、プロファイルルートディレクトリを変更できます:

Selenium v4.10

    @Test
    public void installAddon() {

注意: Javaでは、システムプロパティを使用してログレベルを設定することもできます:
プロパティキー: GeckoDriverService.GECKO_DRIVER_PROFILE_ROOT
プロパティ値: プロファイルルートディレクトリへのパスを表す文字列

特別な機能

アドオン

Chromeとは異なり、Firefoxの拡張機能はCapabilityの一部として追加されるのではなく、ドライバーの起動後に作成されます。

Chromeとは異なり、Firefoxの拡張機能はこの問題に記載されているように、機能の一部として追加されるのではなく、ドライバーの起動後に作成されます。

T以下の例はローカルWebDriver用です。リモートWebDriverについては、Remote WebDriverページを参照してください。

インストール

Mozilla Add-Onsページ から取得する署名付きxpiファイル

アンインストール

アドオンをアンインストールするには、そのIDを知る必要があります。 IDはアドオンインストール時の戻り値から取得できます。

署名なしのインストール

未完成または未公開の拡張機能を使用する場合、署名されていない可能性があります。 そのため、“一時的なもの” としてのみインストールできます。 これは、zipファイルまたはディレクトリを渡すことで実行できます。ディレクトリの例を次に示します。

ページ全体のスクリーンショット

以下の例はローカルWebDriver用です。リモートWebDriverについては、Remote WebDriverページを参照してください。

コンテキスト

以下の例はローカルWebDriver用です。リモートWebDriverについては、Remote WebDriverページを参照してください。

Note: As of Firefox 138, geckodriver needs to be started with the argument --allow-system-access to switch the context to CHROME.