Collections:
Load WebDriver for Different Browsers in Python
How to Load WebDriver for Different Browsers Dynamically in Python?
✍: FYIcenter.com
You can write a Python program with Selenium Client Python API to
Load WebDriver for Different Browsers Dynamically
This can be done by specifying the WebDriver server program path name
when initializing the WebDriver client object.
1. Make sure you have browser drivers installed locally in a single folder:
C:\fyicenter> dir \fyicenter\selenium
8,393,728 chromedriver.exe
14,478,647 geckodriver.exe
149,176 MicrosoftWebDriver.exe
2. Enter the following program, WebDriverLoader.py, that offers a function to load WebDriver by browser name:
C:\fyicenter> type WebDriverLoader.py
# WebDriverLoader.py
# Copyright (c) FYIcenter.com
from selenium.webdriver import Chrome
from selenium.webdriver import Edge
from selenium.webdriver import Firefox
import sys
def load(name):
if (name=="Chrome"):
driver = Chrome("\\fyicenter\\selenium\\chromedriver.exe")
elif (name=="Edge"):
driver = Edge("\\fyicenter\\selenium\\MicrosoftWebDriver.exe")
else:
print("ERROR: Invalid browser name: "+name)
return driver
driver = load(sys.argv[1])
driver.get("http://www.google.com")
driver.quit()
3. Test with Chrome and Edge browsers:
C:\fyicenter> python WebDriverLoader.py Chrome C:\fyicenter> python WebDriverLoader.py Edge
You will see both browsers loaded correctly.
⇒ Retrieve Web Page Title with WebDriver in Python
⇐ Using Selenium WebDriver Client Python API
2019-10-27, 1801🔥, 0💬
Popular Posts:
Where to find online test tools? FYIcenter.com has prepared a number of online test tools: Data Look...
How to see my IP address Host Name? To help you to see your IP Address Host Name, FYIcenter.com has ...
How to generate IP Addresses? To help you to obtain some IP addresses for testing purpose, FYIcenter...
Where to find tutorials on Apache JMeter test tool? I want to know how to use Apache JMeter. Here is...
How to Override a JMeter Variable from Command Line? I want to run the same test plan multiple times...