2 leer cl leer_cl 于 2017.01.10 17:14 提问

Python+Selenium打不开IEDriver,是什么原因呐,求助!!

【环境信息】
Python3.6+Selenium3.0.2+IE10+win7

【问题描述】

1、用如下代码打不开IE浏览器,但是能打开火狐浏览器
import unittest
import os
from selenium import webdriver

class TestAutoMethods(unittest.TestCase):
#打开Firefox浏览器
def test_openbrower(self):
browser = webdriver.Firefox()
browser.get("http://www.baidu.com")

def test_FirstVase(self):
    #ie_driver = os.path.abspath(r"C:\Program Files(x86)\Internet Explorer\IEDriverServer.exe")
    #os.environ["webdriver.ie.driver"] = ie_driver
    browser = webdriver.Ie()
    browser.get("http://www.youdao.com")

if name == '__main__':
unittest.main()

2、报错信息
Error
Traceback (most recent call last):
File "D:\Users\chenle\PycharmProjects\untitled\test\FirstExam.py", line 14, in test_FirstVase
browser = webdriver.Ie()
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\ie\webdriver.py", line 57, in init
desired_capabilities=capabilities)
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in init
self.start_session(desired_capabilities, browser_profile)
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 234, in execute
response = self.command_executor.execute(driver_command, params)
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 408, in execute
return self._request(command_info[0], url, body=data)
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 478, in _request
resp = opener.open(request, timeout=self._timeout)
File "C:\Program Files\Python36\lib\urllib\request.py", line 526, in open
response = self._open(req, data)
File "C:\Program Files\Python36\lib\urllib\request.py", line 544, in _open
'_open', req)
File "C:\Program Files\Python36\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "C:\Program Files\Python36\lib\urllib\request.py", line 1346, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "C:\Program Files\Python36\lib\urllib\request.py", line 1321, in do_open
r = h.getresponse()
File "C:\Program Files\Python36\lib\http\client.py", line 1331, in getresponse
response.begin()
File "C:\Program Files\Python36\lib\http\client.py", line 297, in begin
version, status, reason = self._read_status()
File "C:\Program Files\Python36\lib\http\client.py", line 266, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

2个回答

sylgdxsgx
sylgdxsgx   2017.01.12 13:02

需要IE的驱动IEDriverServer

sylgdxsgx
sylgdxsgx   2017.01.12 13:01

把驱动放到Python\Python35\Scripts目录下

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!