首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >模式下的Python Selenium Edge浏览器

模式下的Python Selenium Edge浏览器
EN

Stack Overflow用户
提问于 2021-08-02 07:20:33
回答 2查看 2.3K关注 0票数 2

我有一个与is兼容的网站。我们激活了边缘Internet模式选项,但im无法使用Selenium处理该网站。在Selenium中有使用IE模式和边缘的方法吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-08-03 03:23:03

您需要从此链接下载推荐版本的IE驱动服务器,然后参考下面的代码,以便在Python中使用Selenium中的边缘IE模式:

代码语言:javascript
复制
from selenium import webdriver

ieOptions = webdriver.IeOptions()
ieOptions.add_additional_option("ie.edgechromium", True)
ieOptions.add_additional_option("ie.edgepath",'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe')
driver = webdriver.Ie(executable_path='E:\webdriver\IEDriverServer.exe', options=ieOptions)

driver.maximize_window()
driver.get('https://www.google.com/')

注意:将代码中的路径更改为您自己的路径。

结果:

票数 2
EN

Stack Overflow用户

发布于 2021-08-02 12:30:34

目前没有用于Python的边缘浏览器IE模式选项,但是在C#中有一个选项

如果您熟悉C#,可以按照以下步骤操作

从IEDriverServer下载最新版本的硒位

使用Visual创建一个C#控制台项目。

从NuGet包管理器安装Selenium.WebDriver 3.141.0 Nuget包。

将下面的代码添加到项目中并修改路径。

代码语言:javascript
复制
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..."; 
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68617785

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档