0

I have this two functions:

def get_chromedriver(headless = False):
    import os
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    options = Options()
    options.binary_location = '/usr/bin/google-chrome'
    options.add_argument('user-data-dir=' + os.environ['HOME'] + '/.config/chromedriver')
    options.add_experimental_option('detach', True)
    options.add_experimental_option('excludeSwitches', ['enable-automation'])
    options.add_experimental_option('useAutomationExtension', False)
    options.headless = headless
    driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver', options=options)
    return driver

def get_firefoxdriver(headless = False):
    import os
    from selenium import webdriver
    from selenium.webdriver.firefox.options import Options
    options = Options()
    options.binary_location = '/usr/bin/firefox'
    options.add_argument('user-data-dir=' + os.environ['HOME'] + '/.config/firefoxdriver')
    options.add_experimental_option('detach', True)
    options.add_experimental_option('excludeSwitches', ['enable-automation'])
    options.add_experimental_option('useAutomationExtension', False)
    options.headless = headless
    driver = webdriver.Firefox(executable_path='/usr/bin/geckodriver', options=options)
    return driver

get_chromedriver function works perfectly but not get_firefoxdriver, which is a copy of the get_chromedriver function.
How can I make the get_firefoxdriver function functionally equivalent to the get_chromedriver function, except for the paths, the webdriver and the browser used?

Mario Palumbo
  • 693
  • 8
  • 32
  • You can not switch to chromedrive from firefox in a single execution, I hope that is clear with you. – cruisepandey Jun 07 '21 at 10:40
  • Quite the opposite. I copied the function for Chrome, in order to create the function for Firefox. The function for Chrome works perfectly, it is the one for Firefox that does not work. – Mario Palumbo Jun 07 '21 at 10:42
  • yeah it was vice-versa that I did not write, But what is the intention for having both of them in a single project ?Is it cross browser testing ? – cruisepandey Jun 07 '21 at 10:43
  • No, one can choose whether to use Firefox or Chrome for automations, but Chrome is not the goal of this question, I only mentioned it because I took it as a reference to create the function for Firefox. – Mario Palumbo Jun 07 '21 at 10:47
  • @cruisepandey Okay, I've made the question clearer. – Mario Palumbo Jun 07 '21 at 10:58

1 Answers1

0

Firefox webdriver does not have the same instance methods as the Chrome webdriver. I see that in your Firefox driver creation function you are calling "detach" and "exludeSwitches" options, however if you take a look at the Firefox documentation you won't find those options whereas the same are available in the Chrome documentation.

There are pros and cons in using each driver, and as in every case the solution should match the use case.