简体   繁体   中英

Opening Firefox in python using selenium

My System: Ubuntu 14.04

Firefox version: 45.0

selenium package: 3.4.2

I have geckodriver in PATH. Selenium is installed. But when I run:

from selenium import webdriver
d = webdriver.Firefox()

I get an error:

d = webdriver.Firefox()
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-2-b37f2497d2bf> in <module>()
----> 1 d = webdriver.Firefox()

/home/jsingla/anaconda2/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.pyc in __init__(self, firefox_profile, firefox_binary, timeout, capabilities, proxy, executable_path, firefox_options, log_path)
    140             capabilities.pop("marionette")
    141             self.service = Service(executable_path, log_path=log_path)
--> 142             self.service.start()
    143 
    144             capabilities.update(firefox_options.to_capabilities())

/home/jsingla/anaconda2/lib/python2.7/site-packages/selenium/webdriver/common/service.pyc in start(self)
     72             self.process = subprocess.Popen(cmd, env=self.env,
     73                                             close_fds=platform.system() != 'Windows',
---> 74                                             stdout=self.log_file, stderr=self.log_file)
     75         except TypeError:
     76             raise

/home/jsingla/anaconda2/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
    388                                 p2cread, p2cwrite,
    389                                 c2pread, c2pwrite,
--> 390                                 errread, errwrite)
    391         except Exception:
    392             # Preserve original exception in case os.close raises.

/home/jsingla/anaconda2/lib/python2.7/subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
   1022                         raise
   1023                 child_exception = pickle.loads(data)
-> 1024                 raise child_exception
   1025 
   1026 

OSError: [Errno 20] Not a directory

Can anyone tell me what is wrong.

Initially I had problem with missing geckodriver but once I added that to path, I am getting above error.

Similar question answered here: https://stackoverflow.com/a/40399367/4206154

Make sure the geckodriver path is the folder path that contains geckodriver (not the actual executable file path).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM