简体   繁体   中英

How to open Microsoft Edge in Internet Explorer(IE) Mode using python and selenium?

I have a webpage in which popup only opens in internet explorer and not in other browsers including chrome, fire fox and edge. The only solution that I have to extract data from such pop up in headless mode is to load the page in edge in internet explorer mode. However I am not able to switch to internet explorer mode in edge using python. Is there any way this can be done? Image showing the settings that needed to be changed:

在此处输入图像描述

From the description, I understand that you want to launch the Edge browser with IE mode using Selenium Python code.

At present, we can only launch the Edge browser with IE mode using Selenium C# code.

If you are available to use selenium with C# language then you can refer to the steps below.

  1. Download the latest version of IEDriverServer from the Selenium site .
  2. Create a C# console project using Visual Studio.
  3. Install Selenium.WebDriver 3.141.0 NuGet package from Nuget package manager.
  4. Add the code below to the project and modify the paths.

static void Main(string[] args) 
{ 
    var dir = "{FULL_PATH_TO_IEDRIVERSERVER}"; 
    var driver = "IEDriverServer.exe"; 
    if (!Directory.Exists(dir) || !File.Exists(Path.Combine(dir, driver))) 
    { 
        Console.WriteLine("Failed to find {0} in {1} folder.", dir, driver); 
        return; 
    } 

    var ieService = InternetExplorerDriverService.CreateDefaultService(dir, driver); 
    var ieOptions = new InternetExplorerOptions{}; 
    ieOptions.AddAdditionalCapability("ie.edgechromium", true); 
    ieOptions.AddAdditionalCapability("ie.edgepath", "{FULL_PATH_TO_MSEDGE.EXE}"); 

    var webdriver = new InternetExplorerDriver(ieService, ieOptions, TimeSpan.FromSeconds(30)); 
    webdriver.Url = "http://Your_Site_URL_here..."; 
}

  1. Run the project to test.

Notes:

  1. Make sure to close all the Edge browser tabs and windows before running the code.
  2. Use full paths in the code.

For example: ieOptions.AddAdditionalCapability("ie.edgepath", @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"); .

Helpful references:

  1. Automating Internet Explorer mode
  2. webdriver-edge-ie-mode.cs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM