`
收藏列表
标题 标签 来源
python selenium
from selenium import selenium
import time

class test():
    def __init__(self):
        pass
    def OpenBrower(self, browertype, url, uri):
        self.selenium = selenium("localhost","4445",browertype,url)
        sel = self.selenium
        sel.start()
        sel.open(uri)
    def Search(self,content):
        sel = self.selenium
        sel.type("id=kw",content)
        time.sleep("30000")
    def CloseBrower(self):
        sel = self.selenium
        sel.close()    
if __name__ == "__main__":
    sel = test()
    sel.OpenBrower("*firefox","www.baidu.com","/")
    sel.Search("123,tdp")

出现如下错误
Traceback (most recent call last):
  File "C:\Users\TDP\Desktop\test.py", line 21, in <module>
    sel.OpenBrower("*firefox","www.baidu.com","/")
  File "C:\Users\TDP\Desktop\test.py", line 10, in OpenBrower
    sel.start()
  File "D:\selenium-2.28.0\py\selenium\selenium.py", line 189, in start
    result = self.get_string("getNewBrowserSession", start_args)
  File "D:\selenium-2.28.0\py\selenium\selenium.py", line 223, in get_string
    result = self.do_command(verb, args)
  File "D:\selenium-2.28.0\py\selenium\selenium.py", line 217, in do_command
    raise Exception, data
Exception: Failed to start new browser session: Error while launching browser

原因:URL地址错误sel.OpenBrower("*firefox","www.baidu.com","/")改为sel.OpenBrower("*firefox","http://www.baidu.com","/")


附:支持的浏览器
Supported browsers include:
  *firefox
  *mock
  *firefoxproxy
  *pifirefox
  *chrome
  *iexploreproxy
  *iexplore
  *firefox3
  *safariproxy
  *googlechrome
  *konqueror
  *firefox2
  *safari
  *piiexplore
  *firefoxchrome
  *opera
  *webdriver
  *iehta
  *custom
Global site tag (gtag.js) - Google Analytics