尝试启动Firefox时出现Python Selenium错误 [英] Python selenium error when trying to launch firefox
问题描述
尝试在ipython Notebook中使用Selenium打开Firefox时出现错误.我环顾四周,发现了类似的错误,但没有与我得到的错误完全匹配的错误.有人知道这个问题可能是什么以及我如何解决?我正在使用Firefox 22.
我输入的代码如下:
from selenium import webdriver
driver = webdriver.Firefox()
代码返回的错误如下:
WindowsError Traceback (most recent call last)
<ipython-input-7-fd567e24185f> in <module>()
----> 1 driver = webdriver.Firefox()
C:\Anaconda\lib\site-packages\selenium\webdriver\firefox\webdriver.pyc in __init__(self, firefox_profile, firefox_binary, timeout, capabilities, proxy)
56 RemoteWebDriver.__init__(self,
57 command_executor=ExtensionConnection("127.0.0.1", self.profile,
---> 58 self.binary, timeout),
59 desired_capabilities=capabilities)
60 self._is_remote = False
C:\Anaconda\lib\site-packages\selenium\webdriver\firefox\extension_connection.pyc in __init__(self, host, firefox_profile, firefox_binary, timeout)
45 self.profile.add_extension()
46
---> 47 self.binary.launch_browser(self.profile)
48 _URL = "http://%s:%d/hub" % (HOST, PORT)
49 RemoteConnection.__init__(
C:\Anaconda\lib\site-packages\selenium\webdriver\firefox\firefox_binary.pyc in launch_browser(self, profile)
45 self.profile = profile
46
---> 47 self._start_from_profile_path(self.profile.path)
48 self._wait_until_connectable()
49
C:\Anaconda\lib\site-packages\selenium\webdriver\firefox\firefox_binary.pyc in _start_from_profile_path(self, path)
71
72 Popen(command, stdout=PIPE, stderr=STDOUT,
---> 73 env=self._firefox_env).communicate()
74 command[1] = '-foreground'
75 self.process = Popen(
C:\Anaconda\lib\subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
677 p2cread, p2cwrite,
678 c2pread, c2pwrite,
--> 679 errread, errwrite)
680
681 if mswindows:
C:\Anaconda\lib\subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
894 env,
895 cwd,
--> 896 startupinfo)
897 except pywintypes.error, e:
898 # Translate pywintypes.error to WindowsError, which is
WindowsError: [Error 2] The system cannot find the file specified
尝试在初始化Firefox()
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('path/to/binary')
driver = webdriver.Firefox(firefox_binary=binary)
FirefoxDriver查找的默认路径为%PROGRAMFILES%\Mozilla Firefox\firefox.exe
.参见 FirefoxDriver
或将Firefox二进制文件的路径添加到Windows的 PATH .>
I am getting an error when trying to open Firefox using Selenium in ipython notebook. I've looked around and have found similar errors but nothing that exactly matches the error I'm getting. Anybody know what the problem might be and how I fix it? I'm using Firefox 22.
The code I typed in was as follows:
from selenium import webdriver
driver = webdriver.Firefox()
The error the code returns is as follows:
WindowsError Traceback (most recent call last)
<ipython-input-7-fd567e24185f> in <module>()
----> 1 driver = webdriver.Firefox()
C:\Anaconda\lib\site-packages\selenium\webdriver\firefox\webdriver.pyc in __init__(self, firefox_profile, firefox_binary, timeout, capabilities, proxy)
56 RemoteWebDriver.__init__(self,
57 command_executor=ExtensionConnection("127.0.0.1", self.profile,
---> 58 self.binary, timeout),
59 desired_capabilities=capabilities)
60 self._is_remote = False
C:\Anaconda\lib\site-packages\selenium\webdriver\firefox\extension_connection.pyc in __init__(self, host, firefox_profile, firefox_binary, timeout)
45 self.profile.add_extension()
46
---> 47 self.binary.launch_browser(self.profile)
48 _URL = "http://%s:%d/hub" % (HOST, PORT)
49 RemoteConnection.__init__(
C:\Anaconda\lib\site-packages\selenium\webdriver\firefox\firefox_binary.pyc in launch_browser(self, profile)
45 self.profile = profile
46
---> 47 self._start_from_profile_path(self.profile.path)
48 self._wait_until_connectable()
49
C:\Anaconda\lib\site-packages\selenium\webdriver\firefox\firefox_binary.pyc in _start_from_profile_path(self, path)
71
72 Popen(command, stdout=PIPE, stderr=STDOUT,
---> 73 env=self._firefox_env).communicate()
74 command[1] = '-foreground'
75 self.process = Popen(
C:\Anaconda\lib\subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
677 p2cread, p2cwrite,
678 c2pread, c2pwrite,
--> 679 errread, errwrite)
680
681 if mswindows:
C:\Anaconda\lib\subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
894 env,
895 cwd,
--> 896 startupinfo)
897 except pywintypes.error, e:
898 # Translate pywintypes.error to WindowsError, which is
WindowsError: [Error 2] The system cannot find the file specified
Try specify your Firefox binary when initialize Firefox()
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('path/to/binary')
driver = webdriver.Firefox(firefox_binary=binary)
The default path FirefoxDriver looking for is at %PROGRAMFILES%\Mozilla Firefox\firefox.exe
. See FirefoxDriver
Or add your path of Firefox binary to Windows' PATH.
这篇关于尝试启动Firefox时出现Python Selenium错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!