Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add driver options in Python Selenium under OOP structure

I have one run.py file that I execute:

from tasks.tasks import Task

with Task() as bot:
    bot.landing_page()

And this is the Task.py file:

from selenium import webdriver

import os


class Task(webdriver.Chrome):

    def __init__(self,
                 driver_path=r";C:\Selenium\drivers"):
        self.driver_path = driver_path
        os.environ['PATH'] += self.driver_path

        super(Task, self).__init__()
        self.implicitly_wait(10)
        self.maximize_window()

    def landing_page(self):
        self.get('https://sampleurl.com')

I would like to add the following code but not particularly sure where and how:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

options = Options()
options.add_argument('--incognito')
options.add_argument('--auto-open-devtools-for-tabs')
options.add_experimental_option('excludeSwitches', ['enable-logging'])
    
driver = webdriver.Chrome(options=options)

Any suggestion would be highly appreciated

>Solution :

add it to the super init function as a named var

from selenium import webdriver

import os


class Task(webdriver.Chrome):

    def __init__(self,
                 driver_path=r";C:\Selenium\drivers"):
        self.driver_path = driver_path
        os.environ['PATH'] += self.driver_path

        options = Options()
        options.add_argument('--incognito')
        options.add_argument('--auto-open-devtools-for-tabs')
        options.add_experimental_option('excludeSwitches', ['enable-logging'])
        super(Task, self).__init__(options=options)
        self.implicitly_wait(10)
        self.maximize_window()

    def landing_page(self):
        self.get('https://sampleurl.com')

more info Here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading