Selenium python 互联网浏览器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24925095/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Selenium python internet explorer
提问by user2242044
I have written a script that opens a web browser using python and Selenium. It works fine with Firefox using the following code:
我编写了一个使用 python 和 Selenium 打开 Web 浏览器的脚本。使用以下代码可以很好地与 Firefox 配合使用:
from selenium import webdriver
driver = webdriver.Firefox()
When I replace Firefox with IE (the suggested value when I start typing), I get the message IEDriver executable needs to be available in the path.
当我用 IE 替换 Firefox(开始输入时的建议值)时,我收到消息 IEDriver executable needs to be available in the path.
from selenium import webdriver
driver = webdriver.IE()
采纳答案by Abhishek Kulkarni
Download IE Drivers based on your OS (Windows 32 or 64 bit)
a. DownloadWindows 32 bits driver
OR
b. DownloadWindows 64 bits driver
Extract the zip and copy IEDriverServer.exe file to some location e.g. E:\IEDriver
Write the following script
from selenium import webdriver browser = webdriver.Ie("e:\IEDriver\IEDriverServer.exe")
Run the script, it should open IE browser...
回答by Kasisnu
It means exactly that. Selenium needsthe executable to work with IE.
A quick google search led me to this. You need to download the executable and place it somewhere visible. Also, taking a look at thisshould help clear some things about PATH variables.
正是这个意思。Selenium需要可执行文件才能与 IE 一起使用。
一个快速的谷歌搜索让我找到了这个。您需要下载可执行文件并将其放在可见的地方。此外,看看这应该有助于清除有关 PATH 变量的一些事情。
回答by Ripon Al Wasim
Selenium with Python bindings in IE:
在 IE 中使用 Python 绑定的 Selenium:
There are 2 ways to run Selenium python tests in Internet Explorer. I'm considering Windows (Windows 10 in my case):
有两种方法可以在 Internet Explorer 中运行 Selenium python 测试。我正在考虑 Windows(在我的情况下是 Windows 10):
Prerequisite: Download IE Driver based on your OS from the site: http://docs.seleniumhq.org/download/
先决条件:从站点下载基于您的操作系统的 IE 驱动程序:http: //docs.seleniumhq.org/download/
Way 1:
方式一:
i) Extract the downloaded zip file in a directory/location of your choice
ii) Set the executable path in your code as below:
i) 将下载的 zip 文件解压缩到您选择的目录/位置
ii) 在您的代码中设置可执行路径,如下所示:
self.driver = webdriver.Ie(executable_path='D:\Selenium_RiponAlWasim\Drivers\IEDriverServer_x64_2.42.0\IEDriverServer.exe')
OR,
或者,
self.driver = webdriver.Ie("D:\Selenium_RiponAlWasim\Drivers\IEDriverServer_x64_2.42.0\IEDriverServer.exe")
Way 2:
方式二:
i) Simply paste the IEDriverServer.exe under /Python/Scripts/ (In my case the folder was: C:\Python36\Scripts)
ii) Now write the simple code as below:
i) 只需将 IEDriverServer.exe 粘贴到 /Python/Scripts/ 下(在我的例子中,文件夹是:C:\Python36\Scripts)
ii) 现在编写如下简单代码:
self.driver = webdriver.Ie()