I looked through the selenium 3 for python documentation but still couldn’t get the difference between these two different driver calls.
webdriver.Firefox()
As per the documentation in selenium.webdriver.firefox.webdriver the following line is the default constructor.
driver = webdriver.Firefox()
While you use the default constructor your script/program expects that the underlying OS PATH variable to contain the absolute path of the GeckoDriver which will start a new local session of Firefox Browser
Again, as per the documentation of selenium.webdriver.firefox.webdriver the complete/full signature of webdriver.Firefox() is as follows:
class selenium.webdriver.firefox.webdriver.WebDriver(firefox_profile=None, firefox_binary=None, timeout=30, capabilities=None, proxy=None, executable_path='geckodriver', options=None, service_log_path='geckodriver.log', firefox_options=None, service_args=None, desired_capabilities=None, log_path=None)
This achieves the following:
So incase your Test Suite includes testcases with multiple version of GeckoDriver, options, Firefox Profiles and Capabilities, you can always specifically mention them while initializing the new WebDriver instance and Web Browsing session.
As an example, if you place geckodriver.exe v0.21.0 within C:\\geckodriver_0_21_0\\
you can mention as follows:
# Windows OS style
driver = webdriver.Firefox(executable_path=r'C:\geckodriver_0_21_0\geckodriver.exe')
# Linux OS style
driver = webdriver.Firefox(executable_path='path/to/geckodriver')
If you define the path for the driver, Functional call look for the file in the path and works accordingly. Second function driver.Firefox() / driver.Chrome()
looks for existing software in the system. if the browser is not present you'll be getting following error.
WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
My take is always use absolute path for the driver definition.
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('path/to/installed firefox binary')
driver = webdriver.Firefox(firefox_binary=binary)