Practical Code Flashcards
what is the recommended way to install a browser driver in order to use it in Selenium?
- to download the Chrome driver (conveniently named chromedriver.exe)
- install (store) that file in a well-known place (directory) on the test workstation.
- add directory to the Path environmental variable
What happens when we create a WebDriver object?
- An API between a script and the web browser is created
- An instance of the web browser is created
Why is Web Driver protocol enabled to run several tests simultaneously or to control several browsers in one script?
Because WebDriver protocol is based on HTTP communication
How do we create a WebDriver object to interact with Chrome Browser?
from selenium import webdriver
driver = webdriver.Chrome()
CODE: To navigate to desired site page
driver.get(‘https://www.python.org’)
CODE: Two useful attributes that the WebDriver object contains to check if the correct page has
been opened:
- driver.current_url
- driver.title
CODE: To close the browser controlled by webdriver
driver.quit()
CODE: To close an specific tab in the controlled web browser instance
driver.close()
What is the safest way to determine which window is the currently open window?
driver.title attribute
CODE: To simulate navigating forward, backward and refresh the web browser
- driver.back()
- driver.forward()
- driver.refresh()
three ways in which a script context can be changed:
- changing browsers
- changing windows/tabs within one browser
- changing frames within one page
where the list of all open tabs (windows) is stored?
An array that can be accessed through the window_handles attribute of the WebDriver object.
CODE: The way to switch between open tabs in a browser (using Windows)
for handle in driver.window_handles:
driver.switch_to.window(handle)
CODE: One way to Open up multiple tabs in Chrome browser (using Windows):
driver.execute_script( “$(window.open(‘’)” )
What is necessary to be able to find elements in a specific frame?
change the context to that particular frame