【问题标题】:Error on Firefox Driver using Selenium/Python使用 Selenium/Python 的 Firefox 驱动程序出错
【发布时间】:2016-04-04 16:06:27
【问题描述】:

尝试使用 Selenium 执行简单的 python 脚本时出现错误。这是脚本和错误以及我的环境信息(我使用的是虚拟环境)。 (当我尝试使用 Chrome 驱动程序时,我得到一个不同的错误)。任何帮助将不胜感激。

// 脚本 //

import mechanize
import urllib2 #requests web pages
from selenium import webdriver
from selenium.common.exceptions import NoSuchAttributeException
from selenium.webdriver.common.keys import Keys #allows us to press keys

import os
import re #regular expressions module

br = mechanize.Browser()
br.set_handle_robots(False)
br.set_handle_refresh(False)
br.addheaders = [('User-agent','Firefox')]

browser = webdriver.Firefox()
browser.get("http://applebees.com")

//错误//

Traceback (most recent call last):
  File "scraper_test.py", line 18, in <module>
    browser = webdriver.Firefox()
  File "/Users/rachael/workspace/rbexplorations/email_scraping_challenge/venv/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 77, in __init__
    self.binary, timeout),
  File "/Users/rachael/workspace/rbexplorations/email_scraping_challenge/venv/lib/python2.7/site-packages/selenium/webdriver/firefox/extension_connection.py", line 49, in __init__
    self.binary.launch_browser(self.profile)
  File "/Users/rachael/workspace/rbexplorations/email_scraping_challenge/venv/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 67, in launch_browser
    self._start_from_profile_path(self.profile.path)
  File "/Users/rachael/workspace/rbexplorations/email_scraping_challenge/venv/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 90, in _start_from_profile_path
    env=self._firefox_env)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

// 关于我的环境的信息 //

python 2.7.10 机械化(0.2.5) 点(7.1.2) 硒(2.48.0) 安装工具 (18.2) 轮子 (0.24.0) OSX 10.11.2

【问题讨论】:

    标签: python python-2.7 selenium selenium-firefoxdriver firefox-driver


    【解决方案1】:

    当 Selenium 在其默认位置找不到 Firefox 安装目录/firefox 可执行文件时,会发生此错误。使用默认设置卸载并重新安装 firefox,然后再次运行脚本。

    一些讨论这个问题的链接:

    https://code.google.com/p/selenium/issues/detail?id=6584

    Selenium: FirefoxProfile fails with not found exception

    How to deal with OSErrors with selenium?

    【讨论】:

      猜你喜欢
      • 2017-09-09
      • 1970-01-01
      • 2017-03-03
      • 1970-01-01
      • 1970-01-01
      • 2021-05-30
      • 1970-01-01
      • 2014-01-03
      • 2014-11-05
      相关资源
      最近更新 更多