如何在硒C#中的Chromium Edge Browser中启用IE模式? [英] How to enable IE mode in Chromium Edge Browser in selenium C#?

查看:547
本文介绍了如何在硒C#中的Chromium Edge Browser中启用IE模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Edge中自动化网站,这需要启用IE模式。


下面我正在使用的代码在非IE模式下启动Edge,这将无法正确显示网站。

  Dim edgeDriverService = Microsoft.Edge.SeleniumTools.EdgeDriverService.CreateChromiumService()
Dim edgeOptions =新Microsoft.Edge.SeleniumTools.EdgeOptions()
edgeOptions.PageLoadStrategy = PageLoadStrategy.Normal
edgeOptions.UseChromium = True
Dim驱动程序作为IWebDriver =新Microsoft.Edge.SeleniumTools.EdgeDriver(edgeDriverService,edgeOptions)
driver.Navigate()。GoToUrl( http ://example.com)

使用 edgeOptions.AddAdditionalCapability( ie.edgechromium ;,True),但是没有用

解决方案

您可以参考


注意:


  1. 在运行代码之前,请确保关闭所有Edge浏览器选项卡和窗口。

  2. 在码。例如: ieOptions.AddAdditionalCapability( ie.edgepath,@ C:\Program Files(x86)\Microsoft\Edge\Application\msedge.exe);


I want to automate a website in Edge which is require IE mode to be enabled. How can launch Edge in IE mode in selenium?

Below code which I currently using is launching Edge in non IE mode, which wont display the website properly.

    Dim edgeDriverService = Microsoft.Edge.SeleniumTools.EdgeDriverService.CreateChromiumService()
    Dim edgeOptions = New Microsoft.Edge.SeleniumTools.EdgeOptions()
    edgeOptions.PageLoadStrategy = PageLoadStrategy.Normal
    edgeOptions.UseChromium = True
    Dim driver As IWebDriver = New Microsoft.Edge.SeleniumTools.EdgeDriver(edgeDriverService, edgeOptions)
    driver.Navigate().GoToUrl("http://example.com")

Tried using edgeOptions.AddAdditionalCapability("ie.edgechromium", True)but it didn't work

解决方案

You could refer to the section Automating Internet Explorer mode in this article about how to use IE mode in Edge Chromium in Selenium C#.

You could refer to the following steps:

  1. Download the latest version of IEDriverServer from Selenium site. Here I use 32 bit Windows IE version 3.150.1.
  2. Make some preparations to use IEDriver according to this.
  3. Create a C# console project using Visual Studio.
  4. Install Selenium.WebDriver 3.141.0 nuget package from Nuget package manager.
  5. Add the code below to the project and modify the paths to your owns in the code:

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://www.example.com"; 
}

  1. Run the project to test:

Notes:

  1. Make sure to close all the Edge browser tabs and window 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");.

这篇关于如何在硒C#中的Chromium Edge Browser中启用IE模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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