问题描述
我有一个网页,其中的弹出窗口仅在Internet Explorer中打开,而不在其他浏览器(包括chrome,fire fox和edge)中打开.我必须以无头模式从此类弹出窗口提取数据的唯一解决方案是在Internet Explorer模式下以边缘加载页面.但是我无法使用python在边缘切换到Internet Explorer模式.有什么办法可以做到吗?该图显示了需要更改的设置:
根据说明,我了解到您想使用 Selenium Python 代码以IE模式启动Edge浏览器.
目前,我们只能使用 Selenium C#代码以IE模式启动Edge浏览器.
如果可以使用C#语言使用硒,则可以参考以下步骤.
- 从硒站点下载最新版本的IEDriverServer.
- 使用Visual Studio创建一个C#控制台项目.
- 从Nuget软件包管理器中安装 Selenium.WebDriver 3.141.0 NuGet软件包.
- 将以下代码添加到项目中并修改路径.
静态void Main(string [] args){var dir ="{FULL_PATH_TO_IEDRIVERSERVER}";var driver ="IEDriverServer.exe";if(!Directory.Exists(dir)||!File.Exists(Path.Combine(dir,驱动程序))){Console.WriteLine(在{1}文件夹中找不到{0}.",目录,驱动程序);返回;}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..." ;;}
- 运行项目进行测试.
注释:
- 在运行代码之前,请确保关闭所有Edge浏览器选项卡和窗口.
- 在代码中使用完整路径.
例如: ieOptions.AddAdditionalCapability("ie.edgepath",@"C:\ Program Files(x86)\ Microsoft \ Edge \ Application \ msedge.exe");
./p>
有用的参考文献:
I have a webpage in which popup only opens in internet explorer and not in other browsers including chrome, fire fox and edge.The only solution that I have to extract data from such pop up in headless mode is to load the page in edge in internet explorer mode. However I am not able to switch to internet explorer mode in edge using python. Is there any way this can be done? Image showing the settings that needed to be changed :
From the description, I understand that you want to launch the Edge browser with IE mode using Selenium Python code.
At present, we can only launch the Edge browser with IE mode using Selenium C# code.
If you are available to use selenium with C# language then you can refer to the steps below.
- Download the latest version of IEDriverServer from the Selenium site.
- 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.
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...";
}
- Run the project to test.
Notes:
- Make sure to close all the Edge browser tabs and windows 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");
.
Helpful references:
这篇关于如何使用python和硒在Internet Explorer(IE)模式下打开Microsoft Edge?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!