简体   繁体   English

有没有办法使用 selenium 和 iedriver 在 Edge 中打开 HTTP Web?

[英]Is there a way to open HTTP web in Edge using selenium and iedriver?

So i'm using this code but if the web is HTTP it opens on IE instead of Edge.所以我正在使用这段代码,但如果网络是 HTTP,它会在 IE 而不是 Edge 上打开。

var ieOptions = new InternetExplorerOptions();
        ieOptions.EdgeExecutablePath = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe";
        IWebDriver driver = new InternetExplorerDriver(ieOptions);

        driver.Url = "some http web";

is there a way to force it on edge?有没有办法强制它在边缘?

You need to download Microsoft Edge Driver and use that.您需要下载 Microsoft Edge 驱动程序并使用它。 The name of the class your code currently uses should give you a hint about why Internet Explorer is being opened:您的代码当前使用的类的名称应该提示您打开 Internet Explorer 的原因:

IWebDriver driver = new InternetExplorerDriver(ieOptions);
                        ^^^^^^^^^^^^^^^^

It is right in the name: InternetExplorer Driver.它的名字是正确的: InternetExplorer Driver。 You are using the web driver for Internet Explorer.您正在使用 Internet Explorer 的 Web 驱动程序。 If you want to automate Edge, you need to use EdgeDriver.如果你想自动化 Edge,你需要使用 EdgeDriver。

I think the curious thing is that Edge is launched when loading an HTTPS URL when using InternetExplorerDriver.我认为奇怪的是,在使用 InternetExplorerDriver 时加载 HTTPS URL 时会启动 Edge。 I suspect there are Windows Policies installed that override Internet Explorer causing Edge to be launched instead.我怀疑安装了覆盖 Internet Explorer 的 Windows 策略,导致 Edge 被启动。

Create InternetExplorerDriver and pass the InternetExplorerOptions :创建InternetExplorerDriver并传递InternetExplorerOptions

var options = new InternetExplorerOptions
{
    AttachToEdgeChrome = true,
    EdgeExecutablePath = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
};

var driver = new InternetExplorerDriver(options);
driver.Url = "https://example.com";

This will open Edge in IE mode... If you don't need IE mode you need to use EdgeDriver instead of InternetExplorerDriver and EdgeOption instead of InternetExplorerOptions这将在 IE 模式下打开 Edge...如果您不需要 IE 模式,则需要使用EdgeDriver而不是InternetExplorerDriverEdgeOption而不是InternetExplorerOptions

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

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