liaoxiping 发表于 2016-6-19 11:01:28

出现如下错误,大神帮帮忙

不能正常打开火狐浏览器,:'(是什么原因呢
# coding = utf-8
... from selenium import webdriver
>>> browser = webdriver.Firefox()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py",
line 85, in __init__
    keep_alive=True)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 90, in __init__
    self.start_session(desired_capabilities, browser_profile)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 177, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 234, in execute
    response = self.command_executor.execute(driver_command, params)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\remote_connectio
n.py", line 401, in execute
    return self._request(command_info, url, body=data)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\remote_connectio
n.py", line 432, in _request
    resp = self._conn.getresponse()
File "C:\Python27\lib\httplib.py", line 1013, in getresponse
    response.begin()
File "C:\Python27\lib\httplib.py", line 402, in begin
    version, status, reason = self._read_status()
File "C:\Python27\lib\httplib.py", line 360, in _read_status
    line = self.fp.readline()
File "C:\Python27\lib\socket.py", line 430, in readline
    data = recv(1)
socket.error:
>>> browser.get("http://www.baidu.com")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'browser' is not defined
>>> browser.find_element_by_id("kw").send_keys("selenium")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'browser' is not defined
>>> browser.find_element_by_id("su").click()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'browser' is not defined
>>>

若尘_51 发表于 2016-6-20 08:34:46

NameError: name 'browser' is not defined

你的脚本写错了。引用了未定义的变量

掉渣饼 发表于 2016-6-20 11:42:53

你的火狐浏览器firefox.exe所在的路径是否添加到了环境变量中的Path中呢?

北京狼族 发表于 2016-6-20 12:22:57

你的默认浏览器是IE而不是火狐

清晨一缕阳光 发表于 2016-6-20 12:39:30

把你的脚本贴出来看看。

liaoxiping 发表于 2016-6-21 18:29:58

谢谢大家,问题解决了   因为火狐47不支持
页: [1]
查看完整版本: 出现如下错误,大神帮帮忙