Is there any possibility to run Python + Selenium script without entering the path of an exe file in every single script in Python line:
driver = webdriver.Chrome().
The same question applies to "IE Driver", "Edge Driver" and "Gecko Driver". Can it be done by some general python class and should I create some additional file for it? Or is it a matter of Integrated Development Environment configuration?
I would be grateful for your expert word.
You can change the source code. Just assign the value of executable_path to your chromedriver path. Let me explain -
When you "normally" type this -
driver = webdriver.Chrome(r"path\chromedriver.exe")
The WebDriver object initializes in its class. The class file is located at //selenium_folder/webdriver/chrome/webdriver.py. Inside it, if you notice the __init__ method, it takes an argument of executable_path. So you can simply do -
def __init__(self, executable_path="chromedriver", port=0,
options=None, service_args=None,
desired_capabilities=None, service_log_path=None,
chrome_options=None):
executable_path = "path\chromedriver.exe"
This way, the following code will successfully run the driver -
driver = webdriver.Chrome()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With