Last active
January 3, 2018 15:17
-
-
Save adv27/b53307c64acbdfa3a7ef97d8b4819bec to your computer and use it in GitHub Desktop.
demo selenium with various drivers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| from selenium import webdriver | |
| #path to drivers | |
| DRIVER_PATH = { | |
| 'chrome' : r'PATH/TO/YOUR/CHROME/DRIVER', | |
| 'firefox' : r'PATH/TO/YOUR/FIREFOX/DRIVER', | |
| 'edge' : r'PATH/TO/YOUR/EDGE/DRIVER', | |
| 'safari' : r'PATH/TO/YOUR/SAFARI/DRIVER' | |
| } | |
| if len(sys.argv) is 3: | |
| browser = sys.argv[1].lower() #convert all character to lowercase, fiReFOx | FIREFOX | fireFOX ===> firefox | |
| url = sys.argv[2] | |
| print('Browser: ' + browser + '\n' + 'URL: ' + url) | |
| if browser in DRIVER_PATH: | |
| driver = None | |
| if browser == 'chrome': | |
| driver = webdriver.Chrome(executable_path = DRIVER_PATH[browser]) | |
| elif browser == 'firefox': | |
| driver = webdriver.Firefox(executable_path = DRIVER_PATH[browser]) | |
| elif browser == 'edge': | |
| driver = webdriver.Edge(executable_path = DRIVER_PATH[browser]) | |
| elif browser == 'safari': | |
| driver = webdriver.Safari(executable_path = DRIVER_PATH[browser]) | |
| if driver is not None: | |
| print('Go to ' + url) | |
| driver.get(url) | |
| driver.implicitly_wait(5) #wait for 5 second | |
| print('Exiting . . . . . . ') | |
| driver.quit() #exit | |
| else: | |
| print('Wrong driver!') | |
| else: | |
| print('Wrong argument, please input browser and url') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment