IE 固有の機能

これらは、Microsoft Internet Explorer ブラウザに固有の機能と特徴です。

2022年6月現在、Selenium はスタンドアロンの Internet Explorer のサポートを正式に終了しました。Internet Explorer ドライバは、引き続き Microsoft Edge を「IE 互換モード」で実行することをサポートしています。

特別な考慮事項

IE ドライバは、Selenium プロジェクトが直接メンテナンスしている唯一のドライバです。32 ビット版と 64 ビット版の Internet Explorer 用のバイナリが利用可能ですが、64 ビット版ドライバにはいくつかの既知の制限事項があります。そのため、32 ビット版ドライバを使用することをお勧めします。

Internet Explorer の使用に関する追加情報は、IE Driver Server のページをご覧ください。

オプション

基本的な定義済みオプションを使用して、Internet Explorer 互換モードで Microsoft Edge ブラウザを起動する方法は次のとおりです。

        InternetExplorerOptions options = new InternetExplorerOptions();
        options.attachToEdgeChrome();
        options.withEdgeExecutablePath(getEdgeLocation());
        driver = new InternetExplorerDriver(options);
    options = webdriver.IeOptions()
    options.attach_to_edge_chrome = True
    options.edge_executable_path = edge_bin
    driver = webdriver.Ie(options=options)
            var options = new InternetExplorerOptions();
            options.AttachToEdgeChrome = true;
            options.EdgeExecutablePath = GetEdgeLocation();
            _driver = new InternetExplorerDriver(options);
      options = Selenium::WebDriver::IE::Options.new
      options.attach_to_edge_chrome = true
      options.edge_executable_path = edge_location
      @driver = Selenium::WebDriver.for :ie, options: options

Internet Explorer Driver v4.5.0 以降

  • IE がシステムに存在しない場合(Windows 11 のデフォルト)、上記の 2 つのパラメータを使用する必要はありません。IE Driver は Edge を使用し、Edge を自動的に検出します。
  • IE と Edge の両方がシステムに存在する場合、Edge にアタッチすることのみを設定する必要があります。IE Driver はシステム上の Edge を自動的に検出します。

したがって、IE がシステムにない場合は、以下のみが必要です。

コードを移動

        InternetExplorerOptions options = new InternetExplorerOptions();
        driver = new InternetExplorerDriver(options);
    options = webdriver.IeOptions()
    driver = webdriver.Ie(options=options)
            var options = new InternetExplorerOptions();
            _driver = new InternetExplorerDriver(options);
      options = Selenium::WebDriver::Options.ie
      @driver = Selenium::WebDriver.for :ie, options: options
let driver = await new Builder()
.forBrowser('internet explorer')
.setIEOptions(options)
.build();
val options = InternetExplorerOptions()
val driver = InternetExplorerDriver(options)

異なる機能を持つ一般的なユースケースをいくつか紹介します。

fileUploadDialogTimeout

一部の環境では、Internet Explorer が [ファイルのアップロード] ダイアログを開くときにタイムアウトすることがあります。IEDriver のデフォルトのタイムアウトは 1000 ミリ秒ですが、fileUploadDialogTimeout 機能を使用してタイムアウトを増やすことができます。

コードを移動

InternetExplorerOptions options = new InternetExplorerOptions();
options.waitForUploadDialogUpTo(Duration.ofSeconds(2));
WebDriver driver = new RemoteWebDriver(options);
  
    options = webdriver.IeOptions()
    options.file_upload_timeout = 2000
var options = new InternetExplorerOptions();
options.FileUploadDialogTimeout = TimeSpan.FromMilliseconds(2000);
var driver = new RemoteWebDriver(options);
  
      @options.file_upload_dialog_timeout = 2000
const ie = require('selenium-webdriver/ie');
let options = new ie.Options().fileUploadDialogTimeout(2000);
let driver = await Builder()
          .setIeOptions(options)
          .build(); 
  
val options = InternetExplorerOptions()
options.waitForUploadDialogUpTo(Duration.ofSeconds(2))
val driver = RemoteWebDriver(options)
  

ensureCleanSession

true に設定すると、この機能は、手動またはドライバによって起動された Internet Explorer を含む、実行中のすべての Internet Explorer インスタンスのキャッシュ、ブラウザ履歴、および Cookie をクリアします。デフォルトでは、false に設定されています。

この機能を使用すると、ドライバは IE ブラウザを起動する前にキャッシュがクリアされるまで待機するため、ブラウザの起動中にパフォーマンスが低下します。

この機能は、パラメータとしてブール値を受け入れます。

コードを移動

InternetExplorerOptions options = new InternetExplorerOptions();
options.destructivelyEnsureCleanSession();
WebDriver driver = new RemoteWebDriver(options);
  
    options = webdriver.IeOptions()
    options.ensure_clean_session = True
var options = new InternetExplorerOptions();
options.EnsureCleanSession = true;
var driver = new RemoteWebDriver(options);
  
      @options.ensure_clean_session = true
const ie = require('selenium-webdriver/ie');
let options = new ie.Options().ensureCleanSession(true);
let driver = await Builder()
          .setIeOptions(options)
          .build(); 
  
val options = InternetExplorerOptions()
options.destructivelyEnsureCleanSession()
val driver = RemoteWebDriver(options)
  

ignoreZoomSetting

InternetExplorer ドライバは、ブラウザのズームレベルが 100% であることを想定しています。そうでない場合、ドライバは例外をスローします。このデフォルトの動作は、ignoreZoomSettingtrue に設定することで無効にできます。

この機能は、パラメータとしてブール値を受け入れます。

コードを移動

InternetExplorerOptions options = new InternetExplorerOptions();
options.ignoreZoomSettings();
WebDriver driver = new RemoteWebDriver(options);
  
    options = webdriver.IeOptions()
    options.ignore_zoom_level = True
var options = new InternetExplorerOptions();
options.IgnoreZoomLevel = true;
var driver = new RemoteWebDriver(options);
  
      @options.ignore_zoom_level = true
const ie = require('selenium-webdriver/ie');
let options = new ie.Options().ignoreZoomSetting(true);
let driver = await Builder()
          .setIeOptions(options)
          .build(); 
  
val options = InternetExplorerOptions()
options.ignoreZoomSettings()
val driver = RemoteWebDriver(options)
  

ignoreProtectedModeSettings

新しい IE セッションを起動する際に、保護モードチェックをスキップするかどうか。

設定されておらず、保護モード設定がすべてのゾーンで同じでない場合、ドライバによって例外がスローされます。

機能が true に設定されている場合、テストが不安定になったり、応答しなくなったり、ブラウザがハングアップしたりする可能性があります。ただし、これは依然として次善の策であり、最初の選択肢は、各ゾーンの保護モード設定を実際に手動で設定することである必要があります。ユーザーがこのプロパティを使用している場合、「最大限の努力」のみがサポートされます。

この機能は、パラメータとしてブール値を受け入れます。

コードを移動

InternetExplorerOptions options = new InternetExplorerOptions();
options.introduceFlakinessByIgnoringSecurityDomains();
WebDriver driver = new RemoteWebDriver(options);
  
    options = webdriver.IeOptions()
    options.ignore_protected_mode_settings = True
var options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
var driver = new RemoteWebDriver(options);
  
      @options.ignore_protected_mode_settings = true
const ie = require('selenium-webdriver/ie');
let options = new ie.Options().introduceFlakinessByIgnoringProtectedModeSettings(true);
let driver = await Builder()
          .setIeOptions(options)
          .build(); 
  
val options = InternetExplorerOptions()
options.introduceFlakinessByIgnoringSecurityDomains()
val driver = RemoteWebDriver(options)
  

silent

true に設定すると、この機能は IEDriverServer の診断出力を抑制します。

この機能は、パラメータとしてブール値を受け入れます。

コードを移動

InternetExplorerOptions options = new InternetExplorerOptions();
options.setCapability("silent", true);
WebDriver driver = new InternetExplorerDriver(options);
  
    service = webdriver.IeService(service_args=["--silent"])
    driver = webdriver.Ie(service=service)
InternetExplorerOptions options = new InternetExplorerOptions();
options.AddAdditionalInternetExplorerOption("silent", true);
IWebDriver driver = new InternetExplorerDriver(options);
  
      @options.silent = true
const {Builder,By, Capabilities} = require('selenium-webdriver');
let caps = Capabilities.ie();
caps.set('silent', true);

(async function example() {
    let driver = await new Builder()
        .forBrowser('internet explorer')
        .withCapabilities(caps)
        .build();
    try {
        await driver.get('http://www.google.com/ncr');
    }
    finally {
        await driver.quit();
    }
})();
  
import org.openqa.selenium.Capabilities
import org.openqa.selenium.ie.InternetExplorerDriver
import org.openqa.selenium.ie.InternetExplorerOptions

fun main() {
    val options = InternetExplorerOptions()
    options.setCapability("silent", true)
    val driver = InternetExplorerDriver(options)
    try {
        driver.get("https://google.com/ncr")
        val caps = driver.getCapabilities()
        println(caps)
    } finally {
        driver.quit()
    }
}
  

コマンドラインオプション

Internet Explorer には、ブラウザのトラブルシューティングと構成を可能にするいくつかのコマンドラインオプションが含まれています。

以下に、サポートされているコマンドラインオプションをいくつか説明します。

  • -private : IE をプライベートブラウジングモードで起動するために使用します。これは、IE 8 以降のバージョンで動作します。

  • -k : Internet Explorer をキオスクモードで起動します。ブラウザは、アドレスバー、ナビゲーションボタン、またはステータスバーを表示しない最大化されたウィンドウで開きます。

  • -extoff : IE をアドオンなしモードで起動します。このオプションは、特にブラウザアドオンの問題をトラブルシューティングするために使用されます。IE 7 以降のバージョンで動作します。

注: コマンドライン引数を機能させるには、forceCreateProcessApi を有効にする必要があります。

コードを移動

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerOptions;

public class ieTest {
    public static void main(String[] args) {
        InternetExplorerOptions options = new InternetExplorerOptions();
        options.useCreateProcessApiToLaunchIe();
        options.addCommandSwitches("-k");
        InternetExplorerDriver driver = new InternetExplorerDriver(options);
        try {
            driver.get("https://google.com/ncr");
            Capabilities caps = driver.getCapabilities();
            System.out.println(caps);
        } finally {
            driver.quit();
        }
    }
}
  
    options = webdriver.IeOptions()
    options.add_argument("-private")

    driver = webdriver.Ie(options=options)
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;

namespace ieTest {
 class Program {
  static void Main(string[] args) {
   InternetExplorerOptions options = new InternetExplorerOptions();
   options.ForceCreateProcessApi = true;
   options.BrowserCommandLineArguments = "-k";
   IWebDriver driver = new InternetExplorerDriver(options);
   driver.Url = "https://google.com/ncr";
  }
 }
}
  
      @options.add_argument('-k')
const ie = require('selenium-webdriver/ie');
let options = new ie.Options();
options.addBrowserCommandSwitches('-k');
options.addBrowserCommandSwitches('-private');
options.forceCreateProcessApi(true);

driver = await env.builder()
          .setIeOptions(options)
          .build();
  
import org.openqa.selenium.Capabilities
import org.openqa.selenium.ie.InternetExplorerDriver
import org.openqa.selenium.ie.InternetExplorerOptions

fun main() {
    val options = InternetExplorerOptions()
    options.useCreateProcessApiToLaunchIe()
    options.addCommandSwitches("-k")
    val driver = InternetExplorerDriver(options)
    try {
        driver.get("https://google.com/ncr")
        val caps = driver.getCapabilities()
        println(caps)
    } finally {
        driver.quit()
    }
}
  

forceCreateProcessApi

CreateProcess API を使用して Internet Explorer を強制的に起動します。デフォルト値は false です。

IE 8 以降の場合、このオプションには「TabProcGrowth」レジストリ値を 0 に設定する必要があります。

コードを移動

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerOptions;

public class ieTest {
    public static void main(String[] args) {
        InternetExplorerOptions options = new InternetExplorerOptions();
        options.useCreateProcessApiToLaunchIe();
        InternetExplorerDriver driver = new InternetExplorerDriver(options);
        try {
            driver.get("https://google.com/ncr");
            Capabilities caps = driver.getCapabilities();
            System.out.println(caps);
        } finally {
            driver.quit();
        }
    }
}
  
    options = webdriver.IeOptions()
    options.force_create_process_api = True

    driver = webdriver.Ie(options=options)
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;

namespace ieTest {
 class Program {
  static void Main(string[] args) {
   InternetExplorerOptions options = new InternetExplorerOptions();
   options.ForceCreateProcessApi = true;
   IWebDriver driver = new InternetExplorerDriver(options);
   driver.Url = "https://google.com/ncr";
  }
 }
}
  
      @options.force_create_process_api = true
const ie = require('selenium-webdriver/ie');
let options = new ie.Options();
options.forceCreateProcessApi(true);

driver = await env.builder()
          .setIeOptions(options)
          .build();
  
import org.openqa.selenium.Capabilities
import org.openqa.selenium.ie.InternetExplorerDriver
import org.openqa.selenium.ie.InternetExplorerOptions

fun main() {
    val options = InternetExplorerOptions()
    options.useCreateProcessApiToLaunchIe()
    val driver = InternetExplorerDriver(options)
    try {
        driver.get("https://google.com/ncr")
        val caps = driver.getCapabilities()
        println(caps)
    } finally {
        driver.quit()
    }
}
  

サービス

すべてのブラウザに共通のサービス設定については、サービスページで説明しています。

ログ出力

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

ファイル出力

ログ出力を特定のファイルに保存するように変更するには

Selenium v4.10

                .withLogFile(getLogLocation())

: Java では、システムプロパティによるファイル出力の設定も可能です。
プロパティキー: InternetExplorerDriverService.IE_DRIVER_LOGFILE_PROPERTY
プロパティ値: ログファイルへのパスを表す文字列

    service = webdriver.IeService(log_output=log_path, log_level="INFO")

    driver = webdriver.Ie(service=service)

コンソール出力

ログ出力をコンソールに STDOUT として表示するように変更するには

Selenium v4.10

                .withLogOutput(System.out)

: Java では、システムプロパティによるコンソール出力の設定も可能です。
プロパティキー: InternetExplorerDriverService.IE_DRIVER_LOGFILE_PROPERTY
プロパティ値: DriverService.LOG_STDOUT または DriverService.LOG_STDERR

Selenium v4.11

    service = webdriver.IeService(log_output=subprocess.STDOUT)

    driver = webdriver.Ie(service=service)

ログレベル

利用可能なログレベルは 6 つあります: FATALERRORWARNINFODEBUG、および TRACE。ログ出力が指定されている場合、デフォルトレベルは FATAL です。

                .withLogLevel(InternetExplorerDriverLogLevel.WARN)

: Java では、システムプロパティによるログレベルの設定も可能です。
プロパティキー: InternetExplorerDriverService.IE_DRIVER_LOGLEVEL_PROPERTY
プロパティ値: InternetExplorerDriverLogLevel.DEBUG.toString() 列挙型の文字列表現

    service = webdriver.IeService(log_output=log_path, log_level="WARN")

    driver = webdriver.Ie(service=service)

Selenium v4.10

      service.args << '-log-level=WARN'

サポートファイルのパス

                .withExtractPath(getTempDirectory())
**注**: Java では、システムプロパティによるログレベルの設定も可能です:\ プロパティキー: `InternetExplorerDriverService.IE_DRIVER_EXTRACT_PATH_PROPERTY`\ プロパティ値: サポートファイルディレクトリへのパスを表す文字列

Selenium v4.11

    service = webdriver.IeService(service_args=["–extract-path=" + temp_dir])

    driver = webdriver.Ie(service=service)

Selenium v4.8

      service.args << "–extract-path=#{root_directory}"
最終更新日 2024年12月20日: [py] fix ie code line (#2107) (add39da6446)