CarlP
CarlP

Reputation: 201

selenium webdriver using Google Chrome

Has anyone encoutered this same error when trying to use selenium?

I'm executing the script from a venv, and this is the error

self.driver = webdriver.Chrome(options=options)
TypeError: __init__() got an unexpected keyword argument 'options

This is the code

class LoginToSite ():
    def __init__(self, username, password):
        self.username = username
        self.password = password


        options = webdriver.chromeoptions(options=options)
        options.add_argument("--incognito")

        self.driver = webdriver.Chrome(options=options)
        self.driver.get('https://google.com')
        self.driver.get("https://portal.office.com")
        sleep(2)

        self.driver.find_element_by_id('i0116')\
            .send_keys(self.username)

        self.driver.find_element_by_id('idSIButton9').click()
        sleep(5)

        self.driver.find_element_by_id('passwordInput')\
            .send_keys(self.password)

        self.driver.find_element_by_id('submitButton').click()
        sleep(5)

        self.driver.find_element_by_id('idSIButton9').click()
        sleep(2)

        main_window = self.driver.window_handles[0]
        self.driver.find_element_by_id('ShellPowerApps_link_text').click()
        sleep(10)
        second_window = self.driver.window_handles[1]
        self.driver.switch_to_window(second_window)

        # self.driver.find_element_by_xpath("//img[contains(text(), '')]")\
        #     .click()
        self.driver.find_element_by_xpath("//a[contains(@href,'/apps')]")\
            .click()
        sleep(10)
        self.driver.find_element_by_xpath("//a[contains(@href,'/abc')]")\
            .click()
LoginToSite(uname,pw)

it makes sense since I have not created the options variable but that is what is advised.

please help.

Upvotes: 1

Views: 1953

Answers (2)

theNishant
theNishant

Reputation: 665

Problem with your code:.

options = webdriver.chromeoptions(options=options)

you are using options without actually defining it.

Solution:
just create an object for options().
so instead of

options = webdriver.chromeoptions(options=options)

use

options = Options()

the final code should look like

options = Options()
options.add_argument("--incognito")
self.driver = webdriver.Chrome(options=options)

Upvotes: 3

Arundeep Chohan
Arundeep Chohan

Reputation: 9969

You were inputting a keyword into chromeoptions. You were also using options a keyword for webdriver.chrome switch the name of your variable to option.

option = webdriver.ChromeOptions()
option.add_argument("--incognito")
driver = webdriver.Chrome(options=option)

Upvotes: 1

Related Questions