简体   繁体   English

Selenium c#:如何在特定版本中启动Internet Explorer驱动程序(例如IE8)

[英]Selenium c#: How to launch Internet Explorer driver in a specific version (IE8 for example)

In java it is possible to set an IE version for internet explorer driver by passing Desired Capabilities. 在java中,可以通过传递Desired Capabilities为Internet Explorer驱动程序设置IE版本。 That doesn't work in C#. 这在C#中不起作用。

I would expect it to look something like: 我希望它看起来像:

DesiredCapabilities ieCapabilities = null;
ieCapabilities = DesiredCapabilities.InternetExplorer();
ieCapabilities.SetCapability(CapabilityType.Version, "8");

IWebDriver driver = new InternetExplorerDriver(ieCapabilities);

In c# I cannot pass DesiredCapabilities into InternetExplorerDriver() constructor. 在c#中,我无法将DesiredCapabilities传递给InternetExplorerDriver()构造函数。

The DesiredCapabilities are wrapped up into various Options class for the specific driver. DesiredCapabilities包含在特定驱动程序的各种Options类中。

There is a InternetExplorerOptions class, which allows you to specify extra options for launching IE, and one of the methods on this is AddAdditionalCapability which, will allow you to add any capability you wish to request . 有一个InternetExplorerOptions类,它允许您指定用于启动IE的额外选项,其中一个方法是AddAdditionalCapability ,它允许您添加您想要请求的任何功能。 This means the options contain the capabilities which is then passed down to the driver . 这意味着选项包含的功能随后传递给驱动程序

As for your specific question, no it is not possible. 至于你的具体问题,不可能。 This is also not a limitation of Selenium or the IEDriverServer, but IE itself. 这也不是Selenium或IEDriverServer的限制,而是IE本身。 You cannot, without major hacks, have more than one version of IE on a machine at once. 如果没有重大黑客攻击,你不能同时在一台机器上安装多个版本的IE。 Think about it the other way - whenever you upgrade IE, it uninstalls the previous version. 另一方面考虑一下 - 无论何时升级IE,它都会卸载以前的版本。

It is going to launch the IE you have installed currently. 它将启动您当前安装的IE。 Anything else is pure wrong, and again, it's wrong because you simply cannot have more than one version of IE on a Windows machine at once. 其他任何东西都是纯粹的错误,而且,这是错误的,因为你不能同时在Windows机器上拥有多个版本的IE。

The only way around this is to have separate machines or VM's for each version, or invest in an automated cloud testing framework like SauceLabs. 解决这个问题的唯一方法是为每个版本配备单独的机器或VM,或投资SauceLabs等自动化云测试框架。

edit 编辑

You have also mentioned you wished to use the compatibility mode of IE8 or wondered if that would work when using the IEDriver. 您还提到过您希望使用IE8的兼容模式,或者想知道在使用IED驱动程序时是否可行。

That is something entirely different (pun intended) again. 这是完全不同的(双关语)。

The compatibility engine in IE is not , a true representation of that browsers engine. IE中的兼容性引擎不是该浏览器引擎的真实表示。 Therefore you must think you are running, say, IE9 with IE7 compatibility mode and thus expect IE7 in full - it won't be, even Microsoft say this, and it is to be used for adhoc testing - it is not to be relied on. 因此,你必须认为你正在运行,比如IE9与IE7兼容模式,因此期望IE7完全 - 它不会,甚至微软说这个,它将被用于adhoc测试 - 它不是依赖于。 Therefore, even if you could do this, it would not be a reliable test in even the slightest terms. 因此,即使你做到这一点,即使是最轻微的条款,它也不是一个可靠的测试。

The problem is still not a Selenium issue. 问题仍然不是Selenium问题。 The IEDriver is going to call whatever IE is installed and at which point, it's down to IE to set up a session that Selenium can connect to. IED驱动程序将调用IE安装的任何内容,此时,它将由IE设置为Selenium可以连接的会话。

It's worth mentioning that all the compatibility options you can use with the IEDriver do not affect IE itself, more the creation of the session and how Selenium interacts with it. 值得一提的是,您可以与IED驱动程序一起使用的所有兼容性选项不会影响IE本身,更多的是会话的创建以及Selenium如何与之交互。

At this point, Selenium throws its hands up in the air, there is very little it can do. 在这一点上,Selenium把手举到空中,它几乎无法做到。

With this in mind, Selenium simply cannot force IE to use a certain browser mode. 考虑到这一点,Selenium根本无法强制IE使用某种浏览器模式。 There is no API at all to do this, and thus, it is not easy to do. 完全没有API来做这件事,因此,这并不容易。

The workaround here, is to force IE to view in a compatibility view in the first place. 这里的解决方法是强制IE首先在兼容性视图中查看。 Your options are very limited: 您的选择非常有限:

Force IE9 into browser compatibility view 强制IE9进入浏览器兼容性视图

To instantiate different versions, you can set the version using capability.setVersion to the required version number. 要实例化不同的版本,可以使用capability.setVersion将版本设置为所需的版本号。 At the same time, while starting the node, you need to add the following parameters in the command line: 同时,在启动节点时,需要在命令行中添加以下参数:

browser "browserName=internet explorer,maxInstances=5,platform=WINDOWS, version=8"

For supporting multiple versions at the same node, you can use "-browser" multiple times. 要在同一节点上支持多个版本,可以多次使用“-browser”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在私有模式下运行Internet Explorer Selenium Web驱动程序C# - Running Internet Explorer selenium web driver in private mode c# 如何使用C#中的AutoIT库在具有硒驱动程序的Internet Explorer中下载文件? - How to Download file in Internet Explorer with selenium driver using AutoIT library in C#? 硒和Internet Explorer驱动程序 - Selenium and Internet Explorer Driver 如何使用Selenium Webdriver在Internet Explorer上获取Cookie-C# - How to get cookies on internet explorer using Selenium webdriver - C# Selenium - Visual Studios- C# - 所有(chrome、firefox 和 Internet Explorer)webdrivers 无法启动驱动程序服务 - Selenium - Visual Studios- C# - All (chrome, firefox, and internet explorer) webdrivers unable to start driver service Selenium C#InPrivate模式Internet Explorer - Selenium C# InPrivate Mode Internet Explorer C#Selenium Internet Explorer超时 - c# selenium internet explorer timeout 升级到3.9版后,无法启动Selenium IE驱动程序 - Can't launch Selenium IE Driver after upgrading to version 3.9 IE驱动如何在C# selenium中设置相对路径 - How to set a relative path in C# selenium for IE driver c#硒隐藏Internet Explorer浏览器窗口 - c# selenium hide Internet Explorer browser window
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM