Python3.6+Selenium打不开Ie浏览器

【环境信息】
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

3个回答

需要IE的驱动,驱动下载:IEDriverServer.exe
把它放到Python\Python35\Scripts目录下即可

我也遇到这个问题了,已把IEDriverServer.exe放到Python\Python36\Scripts目录下,添加了环境变量,但是没有解决问题

selenium调用IE稍微麻烦点:

selenium:

1、selenium版本号查看:cmd下输入 :python 然后 help(selenium)

2、下载驱动和本地selenium版本号及操作系统一致的iedriver
3、驱动放在python的Scripts文件目录里

IE:

1、将IE页面缩放设置为100%
2、进入ie浏览器设置(右上角),打开Internet选项,把安全栏中的“启动保护模式”全部(4个)**取消选中**,再在高级栏中取消选中“增强保护模式”

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问