如何使用python和硒在Internet Explorer(IE)模式下打开Microsoft Edge? [英] How to open Microsoft Edge in Internet Explorer(IE) Mode using python and selenium?

查看:186
本文介绍了如何使用python和硒在Internet Explorer(IE)模式下打开Microsoft Edge?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,其中的弹出窗口仅在Internet Explorer中打开,而不在其他浏览器(包括chrome,fire fox和edge)中打开.我必须以无头模式从此类弹出窗口提取数据的唯一解决方案是在Internet Explorer模式下以边缘加载页面.但是我无法使用python在边缘切换到Internet Explorer模式.有什么办法可以做到吗?该图显示了需要更改的设置:

解决方案

根据说明,我了解到您想使用 Selenium Python 代码以IE模式启动Edge浏览器.

目前,我们只能使用 Selenium C#代码以IE模式启动Edge浏览器.

如果可以使用C#语言使用硒,则可以参考以下步骤.

  1. 硒站点下载最新版本的IEDriverServer.
  2. 使用Visual Studio创建一个C#控制台项目.
  3. 从Nuget软件包管理器中安装 Selenium.WebDriver 3.141.0 NuGet软件包.
  4. 将以下代码添加到项目中并修改路径.


 静态void Main(string [] args){var dir ="{FULL_PATH_TO_IEDRIVERSERVER}";var driver ="IEDriverServer.exe";if(!Directory.Exists(dir)||!File.Exists(Path.Combine(dir,驱动程序))){Console.WriteLine(在{1}文件夹中找不到{0}.",目录,驱动程序);返回;}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. 运行项目进行测试.

注释:

  1. 在运行代码之前,请确保关闭所有Edge浏览器选项卡和窗口.
  2. 在代码中使用完整路径.

例如: ieOptions.AddAdditionalCapability("ie.edgepath",@"C:\ Program Files(x86)\ Microsoft \ Edge \ Application \ msedge.exe"); ./p>

有用的参考文献:

  1. 自动化Internet Explorer模式
  2. webdriver-edge-ie-mode.cs

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

这篇关于如何使用python和硒在Internet Explorer(IE)模式下打开Microsoft Edge?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆