-
Notifications
You must be signed in to change notification settings - Fork 2
3. First Script in Selenium with Python
If you have installed Selenium Python in PyCharm , you can start scripting like this
from selenium import webdriver
driver=webdriver.Chrome(executable_path=r'..\chromedriver.exe')
driver.maximize_window()
driver.get("http://zero.webappsecurity.com/")
driver.quit()
Initially, all the basic modules required are imported. The selenium.webdriver module provides all the WebDriver implementations.
from selenium import webdriver
driver=webdriver.Chrome(executable_path=r'..\chromedriver.exe')
On opening chrome browser, browser will be in restore mode that can be maximize with below method
driver.maximize_window()
The driver.get() method will navigate to a page given by the URL. WebDriver will wait until the page has fully loaded before returning control to the script. It’s worth noting that if the page uses a lot of AJAX on load then WebDriver may not know when it has completely loaded.
driver.get("http://zero.webappsecurity.com/")
The driver.quit() method to close the browser
driver.quit()
Refer the .py files in different_browser folder for basic understanding
The following syntax can be used to launch Browser:
driver=webdriver.Chrome(executable_path='URL')
driver=webdriver.Firefox(executable_path='URL')
driver=webdriver.Ie(executable_path='URL')
- driver.close()
The driver.close() command is used to close the current browser window having focus. In case there is only one browser open then calling driver.close() quits the whole browser session. And driver.close() will not terminate the chromedriver.exe in the background
- driver.quit()
The driver.quit() is used to quit the whole browser session along with all the associated browser windows, tabs and pop-ups. And driver.quit() will terminate the chromedriver.exe