What is the difference between webdriver.Firefox() and webdriver.Firefox() in selenium?

What is the difference between webdriver.Firefox() and webdriver.Firefox(<path to gecko executable >) in selenium?



I looked through the selenium 3 for python documentation but still couldn’t get the difference between these two different driver calls.


webdriver.Firefox()



and


webdriver.Firefox(<path to gecko executable >)



when using Selenium?



Since I’m working on a web scrapping project this could help me a lot .




2 Answers
2



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.


driver.Firefox() / driver.Chrome()


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)






firefox_binary has nothing to do with geckodriver

– Andersson
Sep 6 '18 at 8:28


firefox_binary


geckodriver



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:


C:\geckodriver_0_21_0\


# Windows OS style
driver = webdriver.Firefox(executable_path=r'C:geckodriver_0_21_0geckodriver.exe')
# Linux OS style
driver = webdriver.Firefox(executable_path='path/to/geckodriver')



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)