我有一个网页,其中的弹出窗口仅在 Internet Explorer 中打开,而不能在其他浏览器(包括 Chrome、Fire Fox 和 Edge)中打开。
我必须在无头模式下从此类弹出窗口中提取数据的唯一解决方案是在 Internet Explorer 模式下在边缘加载页面。但是我无法使用 python 在 Edge 中切换到 Internet Explorer 模式。有什么办法可以做到这一点吗?显示需要更改的设置的图像:
从描述中,我了解到您想要使用 IE 模式启动 Edge 浏览器硒蟒蛇 code.
目前我们只能使用 IE 模式启动 Edge 浏览器硒 C# code.
如果您可以将selenium与C#语言一起使用,那么您可以参考以下步骤。
- 从以下位置下载最新版本的 IEDriverServer硒站点 https://www.selenium.dev/downloads/.
- 使用 Visual Studio 创建 C# 控制台项目。
- Install 硒.WebDriver 3.141.0来自 Nuget 包管理器的 NuGet 包。
- 将以下代码添加到项目中并修改路径。
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...";
}
- 运行项目进行测试。
Notes:
- 确保在运行代码之前关闭所有 Edge 浏览器选项卡和窗口。
- 在代码中使用完整路径。
例如:ieOptions.AddAdditionalCapability("ie.edgepath", @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe");
.
有用的参考资料:
- 自动化 Internet Explorer 模式 https://blogs.windows.com/msedgedev/2019/11/04/edge-chromium-release-candidate-get-ready/
- webdriver-edge-ie-mode.cs https://gist.github.com/kypflug/4e8291e6ee65929944f8ba74b1575dd8
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)