1

Trying to run selenium with this code but it keeps saying:

No module named 'options' found

Code:

import os
import sys
import subprocess
import pkg_resources
import selenium
from selenium import webdriver
#from selenium import options
import options
chromedriver = r"E:\Users\Yaseen Ahammed\Documents\Python Projects\chromedriver\chromedriver.exe"
#ChromeOptions = new ChromeOptions();
driver=webdriver.Chrome(chromedriver)
#binary_location
options.setBinary(r"E:\Users\Yaseen Ahammed\Documents\Python Projects\chromedriver\Chrome\Application\chrome.exe")

The error is thrown up for the import options line however without it I get the error that options is not defined on the options.setBinary line.

undetected Selenium
  • 151,581
  • 34
  • 225
  • 281
mya205
  • 105
  • 9

3 Answers3

2

This error message...

No module named 'options' found

...implies that the module you are trying to import i.e. options as in:

from selenium import options

isn't found as it is not a valid module.

Further instead of using setBinary() method you need to use the binary_location attribute.


Solution

As you are using ChromeDriver/Chrome there are two solutions to this issue as follows:

  • As you have already used from selenium import webdriver you can:

    from selenium import webdriver
    
    options = webdriver.ChromeOptions()
    options.binary_location = r"E:\Users\Yaseen Ahammed\Documents\Python Projects\chromedriver\Chrome\Application\chrome.exe"    #chrome binary location specified here
    
  • You can also:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    options = Options()
    options.binary_location = r"E:\Users\Yaseen Ahammed\Documents\Python Projects\chromedriver\Chrome\Application\chrome.exe"    #chrome binary location specified here
    

References

You can find a couple of relevant discussions in:

undetected Selenium
  • 151,581
  • 34
  • 225
  • 281
  • @mya205 Check [selenium.webdriver.chrome.options](https://www.selenium.dev/selenium/docs/api/py/webdriver_chrome/selenium.webdriver.chrome.options.html#module-selenium.webdriver.chrome.options) and [selenium.webdriver.chromium.options](https://www.selenium.dev/selenium/docs/api/py/webdriver_chromium/selenium.webdriver.chromium.options.html#module-selenium.webdriver.chromium.options) – undetected Selenium Dec 20 '20 at 14:45
  • 1
    Thanks for this, I checked the python selenium documentation but couldn't find anything about this for the current version that I am on, and knowing that each version change changes lines of code which can be recognised, it's hard to know what still works and what doesn't in newer versions which is why I ended up opening this thread. Is there any official documentation containing each parameter/line of code that can be recognised by the selenium package in python? – mya205 Dec 20 '20 at 14:48
  • 1
    Ok thank you! When I try to do this I am now getting the error that "Message='Options' object has no attribute 'setBinary'" for the "options.setBinary" line. – mya205 Dec 20 '20 at 14:49
  • @mya205 Checkout the updated answer and let me know the status. – undetected Selenium Dec 20 '20 at 14:59
  • 1
    Thank you! I think I've figured it out with "binary_location" as opposed to "setBinary" which is what I saw a lot of people mentioning. Is this difference due to version differences or something else? I noticed a lot of the time code others have mentioned possibly from a year or two ago doesn't seem to work so I'm assuming it's just version differences. It gets really confusing quickly because of these version changes etc so thank you for the help it really is useful. – mya205 Dec 20 '20 at 15:04
  • @mya205 That's all together a different question which needs to be answered in a canonical way. Can you raise a new question as per your new requirement please? Stackoverflow contributors will be happy to help you out. – undetected Selenium Dec 20 '20 at 15:07
1

I believe you can import options for the specific webdriver e.g.

from selenium.webdriver.chrome.options import Options or from selenium.webdriver.firefox.options import Options

Then later you can do options = Options() and then the functions for options should be available

NationBoneless
  • 288
  • 1
  • 10
  • When I try to do this I am now getting the error that "Message='Options' object has no attribute 'setBinary'" for the "options.setBinary" line. – mya205 Dec 20 '20 at 14:49
1

I think you need to import this for the chrome driver.

from selenium.webdriver.chrome.options import Options

After that, you should do this

options = Options()

I believe your problem will be solved.

Munna
  • 19
  • 2
  • When I try to do this I am now getting the error that "Message='Options' object has no attribute 'setBinary'" for the "options.setBinary" line. – mya205 Dec 20 '20 at 14:50