Selenium: AttributeError: 'Options' object has no attribute 'binary'

Created on 6 Sep 2017  路  4Comments  路  Source: SeleniumHQ/selenium

Meta -

OS:

$uname -a
Linux archdeekus 4.11.3-1-ARCH #1 SMP PREEMPT Sun May 28 10:40:17 CEST 2017 x86_64 GNU/Linux

Selenium Version:

$pip3 show selenium
Name: selenium
Version: 3.4.3
Summary: Python bindings for Selenium
Home-page: https://github.com/SeleniumHQ/selenium/
Author: UNKNOWN
Author-email: UNKNOWN
License: Apache 2.0
Location: /usr/lib/python3.6/site-packages
Requires:

Browser:

$firefox -v
Mozilla Firefox 55.0.3

Browser Version:

55.0.3(64-bit)

Expected Behavior - Instance of Firefox starting

Actual Behavior - Error thrown:

```Process Process-1:
Traceback (most recent call last):
File "/usr/lib/python3.6/multiprocessing/process.py", line 249, in _bootstrap
self.run()
File "/usr/lib/python3.6/multiprocessing/process.py", line 93, in run
self._target(self._args, *self._kwargs)
File "ProxLoadMe.py", line 186, in retrieve_source
switcher = parse_file(hoster, name, currthreads, iterator)
File "ProxLoadMe.py", line 197, in parse_file
driver = init_webdriver()
File "ProxLoadMe.py", line 51, in init_webdriver
return webdriver.Firefox(firefox_options=options, log_path="geckodriver.log")
File "/usr/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 118, in __init__
if firefox_options.binary is not None:
AttributeError: 'Options' object has no attribute 'binary'

## Steps to reproduce -

def init_webdriver():
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "/usr/bin/firefox"
options.add_argument("-headless")
return webdriver.Firefox(firefox_options=options, log_path="geckodriver.log")

driver = init_webdriver()
driver.close()

Using options.binary = "/usr/bin/firefox" following error appears:  

Process Process-1:
Traceback (most recent call last):
File "/usr/lib/python3.6/multiprocessing/process.py", line 249, in _bootstrap
self.run()
File "/usr/lib/python3.6/multiprocessing/process.py", line 93, in run
self._target(self._args, *self._kwargs)
File "ProxLoadMe.py", line 186, in retrieve_source
switcher = parse_file(hoster, name, currthreads, iterator)
File "ProxLoadMe.py", line 197, in parse_file
driver = init_webdriver()
File "ProxLoadMe.py", line 51, in init_webdriver
return webdriver.Firefox(firefox_options=options, log_path="geckodriver.log")
File "/usr/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 120, in __init__
if firefox_options.profile is not None:
AttributeError: 'Options' object has no attribute 'profile'

/usr/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py references to /usr/lib/python3.6/site-packages/selenium/webdriver/firefox/options.py, which contains:  

def __init__(self):
self._binary = None
self._preferences = {}
self._profile = None
self._proxy = None
self._arguments = []
self.log = Log()
```
Calling webdriver.Firefox(log_path="geckodriver.log") simply opens Firefox.

Most helpful comment

If you'd read carefully:

from selenium.webdriver.chrome.options import Options

```python
options = Options()

```python
options.binary_location = "/usr/bin/firefox"
options.add_argument("-headless")

```python
return webdriver.Firefox(firefox_options=options, log_path="geckodriver.log")

This Issue was resolved by  *reading*  (it was 2 a.m.)
#### Here is a quick snip that will do the job for you:
```python
from shutil import which
from selenium import webdriver

```python
FIREFOXPATH = which("firefox")
CHROMEPATH = which("chrome") or which("chromium")

```python
def init_webdriver():
    """Simple Function to initialize and configure Webdriver"""
    if FIREFOXPATH != None:
        print(FIREFOXPATH)#cm
        from selenium.webdriver.firefox.options import Options

        options = Options()
        options.binary = FIREFOXPATH
        options.add_argument("-headless")
        return webdriver.Firefox(firefox_options=options, log_path="geckodriver.log")

    elif CHROMEPATH != None:
        print(CHROMEPATH)#cm
        from selenium.webdriver.chrome.options import Options

        options = Options()
        options.binary_location = CHROMEPATH
        options.add_argument("--headless")
return webdriver.Chrome(chrome_options=options, service_args=['--verbose'], service_log_path="chromedriver.log")

Usage:

driver = init_webdriver()
...

Note, the Browser(s) will be started headless, unless you remove the corresponding line

Don't forget to mention.

All 4 comments

Typo killed me here, sorry.

how you solve this? noob here :S

Why is this closed?

If you'd read carefully:

from selenium.webdriver.chrome.options import Options

```python
options = Options()

```python
options.binary_location = "/usr/bin/firefox"
options.add_argument("-headless")

```python
return webdriver.Firefox(firefox_options=options, log_path="geckodriver.log")

This Issue was resolved by  *reading*  (it was 2 a.m.)
#### Here is a quick snip that will do the job for you:
```python
from shutil import which
from selenium import webdriver

```python
FIREFOXPATH = which("firefox")
CHROMEPATH = which("chrome") or which("chromium")

```python
def init_webdriver():
    """Simple Function to initialize and configure Webdriver"""
    if FIREFOXPATH != None:
        print(FIREFOXPATH)#cm
        from selenium.webdriver.firefox.options import Options

        options = Options()
        options.binary = FIREFOXPATH
        options.add_argument("-headless")
        return webdriver.Firefox(firefox_options=options, log_path="geckodriver.log")

    elif CHROMEPATH != None:
        print(CHROMEPATH)#cm
        from selenium.webdriver.chrome.options import Options

        options = Options()
        options.binary_location = CHROMEPATH
        options.add_argument("--headless")
return webdriver.Chrome(chrome_options=options, service_args=['--verbose'], service_log_path="chromedriver.log")

Usage:

driver = init_webdriver()
...

Note, the Browser(s) will be started headless, unless you remove the corresponding line

Don't forget to mention.

Was this page helpful?
0 / 5 - 0 ratings