如何在硒C#中的Chromium Edge Browser中启用IE模式? [英] How to enable IE mode in Chromium Edge Browser in selenium C#?
问题描述
我想在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)
,但是没有用
您可以参考
注意:
- 在运行代码之前,请确保关闭所有Edge浏览器选项卡和窗口。
- 在码。例如:
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:
- Download the latest version of IEDriverServer from Selenium site. Here I use 32 bit Windows IE version 3.150.1.
- Make some preparations to use IEDriver according to this.
- Create a C# console project using Visual Studio.
- Install Selenium.WebDriver 3.141.0 nuget package from Nuget package manager.
- 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";
}
- Run the project to test:
Notes:
- Make sure to close all the Edge browser tabs and window before running the code.
- 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屋!