IE和Chrome不能使用Selenium2 Python [英] IE and Chrome not working with Selenium2 Python
问题描述
我已完成以下步骤:
$ b $ ul
每当我键入:
来自selenium import webdriver
driver = webdriver.Ie()
p
from selenium import webdriver
driver = webdriver.Chrome()
放到Python shell中,没有浏览器弹出,shell冻结了几分钟,然后输出错误信息。
IE错误信息:
selenium.common.exceptions.WebDriverException :消息:'无法连接到IEDriver'
Chrome错误消息:
urllib2.HTTPError:HTTP错误503:服务不可用
使用firefox可以很好地工作。有趣的是,这个过程(IEDriver和ChromeDriver)是通过TaskManager启动的,但是这个窗口永远不会显示出来。 解决方案
在python-selenium中 webdriver.Ie
只是执行 IEDriver.exe 并通过 webdriver连接到它的快捷方式。远程
。例如,您可以从命令行启动 IEDriver.exe :
> IEDriverServer.exe
启动InternetExplorerDriver服务器(64位)
2.39.0.0
监听端口5555
并用以下代码替换 webdriver.Ie()
:
<$ p $ ($ command_executor ='http://127.0.0.1:5555',
desired_capabilities = DesiredCapabilities.INTERNETEXPLORER)`
webdriver.Remote pre>
您将得到相同的结果。
具体而言,您的情况最有可能是您有一些系统代理设置强制它通过代理服务器连接到 127.0.0.1 。可能当您按照 Python中的描述禁用它:Python:在urllib2中禁用http_proxy 可以解决这个问题: I can't seem to open up Google Chrome or Internet Explorer through Selenium 2's Python library. I am using Windows 7, 64 bit. I have completed the following steps: Whenever I type: OR into the Python shell, no browser pops up, the shell just freezes for a couple of minutes and then outputs an error message. IE Error message: Chrome Error message: It works perfectly fine with firefox. The funny thing is, is that the process (IEDriver and ChromeDriver) starts per the TaskManager, but the window never shows up. In python-selenium and replace You will get the same result. Specifically in your case is most likely that you have some system proxy settings that force it connect to 127.0.0.1 through proxy server. Probably when you disable it as described in answer Python: Disable http_proxy in urllib2, you can solve the problem:
这篇关于IE和Chrome不能使用Selenium2 Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
pre $ import $ $ $ b $ import b
$ b $
@contextmanager
def no_proxies():
orig_getproxies = urllib2.getproxies
urllib2.getproxies = lambda:{}
yield
urllib2 .getproxies = orig_getproxies
$ b $ with no_proxies():
driver = selenium.webdriver.Ie()
driver.get(http://google.com)
from selenium import webdriver
driver = webdriver.Ie()
from selenium import webdriver
driver = webdriver.Chrome()
selenium.common.exceptions.WebDriverException: Message: 'Can not connect to the IEDriver'
urllib2.HTTPError: HTTP Error 503: Service Unavailable
webdriver.Ie
is just a shortcut for executing IEDriver.exe and connecting to it through webdriver.Remote
. For example, you could start IEDriver.exe from command line:> IEDriverServer.exe
Started InternetExplorerDriver server (64-bit)
2.39.0.0
Listening on port 5555
webdriver.Ie()
with the following code:webdriver.Remote(command_executor='http://127.0.0.1:5555',
desired_capabilities=DesiredCapabilities.INTERNETEXPLORER)`
import selenium
import urllib2
from contextlib import contextmanager
@contextmanager
def no_proxies():
orig_getproxies = urllib2.getproxies
urllib2.getproxies = lambda: {}
yield
urllib2.getproxies = orig_getproxies
with no_proxies():
driver = selenium.webdriver.Ie()
driver.get("http://google.com")