python调用iewebdriver?报错-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

python调用iewebdriver?报错

爱吃鱼的程序员 2020-06-08 17:33:46 92

想在Python下调用iewebdriver做网页测试,

IEDriverServer.exe 这个已经放进python的目录下面了,谷歌能运行,IE的报错(我用的是IE8,已经关闭保护模式):

Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import os
>>> from selenium import webdriver
>>> from selenium.webdriver.common.keys import Keys
>>> iedriver = "C:\Program Files\Internet Explorer\IEDriverServer.exe"
>>> os.environ["webdriver.ie.driver"] = iedriver
>>> driver.get("http://www.baidu.com")

Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    driver.get("http://www.baidu.com")
NameError: name 'driver' is not defined
>>> driver = webdriver.Ie(iedriver)

Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    driver = webdriver.Ie(iedriver)
  File "F:\Python27\lib\site-packages\selenium\webdriver\ie\webdriver.py", line 57, in __init__
    desired_capabilities=capabilities)
  File "F:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "F:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
  File "F:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 234, in execute
    response = self.command_executor.execute(driver_command, params)
  File "F:\Python27\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 408, in execute
    return self._request(command_info[0], url, body=data)
  File "F:\Python27\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 478, in _request
    resp = opener.open(request, timeout=self._timeout)
  File "F:\Python27\lib\urllib2.py", line 429, in open
    response = self._open(req, data)
  File "F:\Python27\lib\urllib2.py", line 447, in _open
    '_open', req)
  File "F:\Python27\lib\urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "F:\Python27\lib\urllib2.py", line 1228, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "F:\Python27\lib\urllib2.py", line 1201, in do_open
    r = h.getresponse(buffering=True)
  File "F:\Python27\lib\httplib.py", line 1136, in getresponse
    response.begin()
  File "F:\Python27\lib\httplib.py", line 453, in begin
    version, status, reason = self._read_status()
  File "F:\Python27\lib\httplib.py", line 417, in _read_status
    raise BadStatusLine(line)
BadStatusLine: ''



Python
分享到
取消 提交回答
全部回答(1)
  • 爱吃鱼的程序员
    2020-06-08 17:33:57
     
      fromselenium
      
       importwebdriverdriver=webdriver.Ie(
       
        "C:\ProgramFiles\InternetExplorer\IEDriverServer.exe")driver.get(
        
         "http://www.baidu.com")
        
       
      
     
    0 0
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

推荐文章
相似问题
推荐课程