Home > database >  AttributeError: 'Options' object has no attribute 'add_experimental_option'
AttributeError: 'Options' object has no attribute 'add_experimental_option'

Time:10-10

hi guys I hope that you are having a great time. so I'm having this problem when I'm tring to execute this script.

 import selenium.webdriver as webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.options import Options


url = "https://www.google.com/"


chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
#Change chrome driver path accordingly
driver = webdriver.Chrome(
    executable_path = r"C: \drivers\chromedriver.exe", chrome_options =chrome_options)
print (driver.title)

the results in cmd:

 Traceback (most recent call last):
      File "C:\Users\modaw\Desktop\firefox elo\hi.py", line 12, in <module>
        opts.add_experimental_option('debuggerAddress', 'localhost:9222')
    AttributeError: 'Options' object has no attribute 'add_experimental_option'

CodePudding user response:

if you have the same problem try using this string with code

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

opt=Options()
opt.add_experimental_option("debuggerAddress","localhost:8989")
driver = webdriver.Chrome(executable_path="chromedriver.exe",chrome_options=opt)
driver.get("http://google.com")

CodePudding user response:

You need to change the third line to from selenium.webdriver.chrome.options import Options instead of from selenium.webdriver.chrome.options import options since the Options class is uppercase. Otherwise Python will not import it successfully.

Python names are case-sensitive.

Chrome WebDriver Options Methods

  • Related