Interacting With WebDriver
On this page you'll learn about all of the different methods that the Simple Selenium WebDriver class has to offer
Introduction
The WebDriver class contains all of the Simple Selenium functionality wrapped into an easy-to-use class. On this page, you'll learn how to use the WebDriver class in your web-scraping & general automation projects.
List of All Simple Selenium WebDriver Functions
Unwrap Driver
You can get the unwrapped Selenium webdriver object with:
seleniumDriver=driver.driver #Returns unwrapped Selenium webdriver objectClose Driver
You can do a clean shutdown of the webdriver web browser with:
driver.close() #Closes the webdriver & web browser cleanlyClose Active Tab
Close just the active tab:
driver.close_active_tab() #Closes the current active tab or the entire web browser if only one tab is openVisit a Web Page
Visiting a webpage:
driver.visit("https://google.com") #Visits google.com
#Default options:
referrer=False #Whether webdriver should use a referrer before visiting the target page
use_random_delay=True #Delay between visiting referrer website & target website (if referrer!=False)
min_delay=3.0 #Minimum delay between visiting referrer website & target website (if referrer!=False)
max_delay=3.5 #Maximum delay between visiting referrer website & target website (if referrer!=False)
driver.visit("https://domain.com",referrer="https://google.com") #Visits google.com before domain.com, which sets the referrer as google.comFocus Document
Focuses the main document:
driver.focus_document() #Focuses the main top-level documentFocus IFrame
Focuses a target IFrame:
iframeTest=driver.by_id("myTestIframe") #Get some iframe from the page
driver.focus_iframe(iframeTest) #Focuses the main top-level documentFocus Parent IFrame
Focuses the parent document/iframe:
driver.focus_parent_iframe() #Focuses parent frameGet Application Cache
Get application cache:
driver.application_cache() #Returns the application cacheGet Browser Capabilities
Get browser capabilities:
driver.capabilities() #Returns browser capabilitiesGet Desired Browser Capabilities
Get desired browser capabilities:
driver.desired_capabilities() #Returns desired browser capabilitiesGet Page Source
Get the current active page's source code:
driver.page_source() #Returns active page's source codeGet Browser Name
Gets the browser name:
driver.name() #Returns browser nameGet Timeouts
Gets driver timeouts:
driver.timeouts() #Returns timeoutsGet File Detector
Gets file detector:
driver.file_detector() #Returns file detectorGet Virtual Auth ID
Gets virtual authenticator ID:
driver.virtual_authenticator_id() #Returns virtual auth idGet Window Handles
Gets active window handles:
driver.window_handles() #Returns window handlesGet Device Orientation
Gets device orientation:
driver.orientation() #Returns device orientationGet Current Active Window Handle
Gets active window handle:
driver.current_window_handle() #Returns active window handleGet Web Page Title
Gets the title of the current active webpage:
driver.title() #Returns webpage titleGet Mobile Object
Gets the driver's mobile object:
driver.mobile() #Returns driver mobile objGet Log Types
Gets log types:
driver.log_types() #Returns all log typesGet Current URL
Gets the current active page URL:
driver.current_url() #Returns current active page URLGet Base64 Screenshot
Gets a base64 encoded string of screenshot img file:
driver.screenshot_base64() #Returns string with base64 encoded img fileGet PNG Screenshot
Gets a bytes encoded string of screenshot png file:
driver.screenshot_png() #Returns string with bytes encoded png fileSave File Screenshot
Screenshots & saves as a file in target directory:
driver.screenshot("imgs/test.png") #Saves screenshot file in target directory with target filenameAdd Browser Cookie
Adds a cookie dict to browser:
driver.add_cookie({"cookieKey":"cookieValue"}) #Adds cookie to browserAdd Credential
Adds authentication credentials:
driver.add_credential(authenticationObj) #Injects credential to authenticatorAdd Virtual Authenticator
Adds virtual authenticator:
driver.add_virtual_authenticator(authenticationObj) #Injects credential to authenticatorPrevious Page
Go back to previous page:
driver.back() #Goes to the previous webpageDelete All Cookies
Delete all browser cookies:
driver.delete_all_cookies() #Deletes all cookiesDelete Cookie By Name
Delete browser cookie by name:
driver.delete_cookie("cookieName") #Deletes cookie by nameDelete Downloadable Files
Delete downloadable files:
driver.delete_downloadable_files() #Deletes downloadable filesDownload File
Download file by file name & directory:
driver.download_file() #Downloads fileExecute Async Script
Executes JS async script:
driver.execute_async_script("async js script to execute") #Executes JS script async
testElem=driver.by_id("testElement")
driver.execute_async_script("testElem=arguments[0];console.log(testElem);",testElem,testElem2,etc) #Executes async script with webelement(s) Execute Script
Executes JS script:
driver.execute_script("js script to execute") #Executes JS script
testElem=driver.by_id("testElement")
testElem2=driver.by_id("testElement2")
driver.execute_script("testElem=arguments[0];console.log(testElem);",testElem,testElem2,etc) #Executes script with webelement(s) Forward Page
Go forward a page:
driver.forward() #Goes forward one pageFull-Screen Window
Turn browser into full-screen mode:
driver.fullscreen_window() #Turns browser to fullscreen modeGet Cookie By Name
Get cookie by name:
driver.get_cookie("cookieName") #Returns cookie by nameGet All Cookies
Get all cookies from browser:
driver.get_cookies() #Returns all cookiesGet All Credentials
Get all credentials:
driver.get_credentials() #Returns all credentialsGet Downloadable Files
Get downloadable file:
driver.get_downloadable_files() #Returns downloadable filesGet Log By Type
Get log from storage by type:
driver.get_log("logType") #Returns log Get Pinned Scripts
Get pinned scripts:
driver.get_pinned_scripts() #Returns pinned scriptsGet Window Position
Get window position:
driver.get_window_position() #Returns window position of active window handle
#Default options:
windowHandle="current"
driver.get_window_position(anotherWindowHandle) #Returns window position of another window handleGet Window Rect
Gets window rect:
driver.get_window_rect() #Returns window rectGet Window Size
Gets window size:
driver.get_window_size() #Returns window size of active window handle
#Default options:
windowHandle="current"
driver.get_window_size(anotherWindowHandle) #Returns window size of another window handleImplicitly Wait
Wait for x seconds:
driver.implicitly_wait(5) #Waits for 5 secondsMaximize Window
Maximizes the browser window:
driver.maximize_window() #Puts browser into maximized modeMinimize Window
Minimizes the browser window:
driver.minimize_window() #Puts browser into minimized modePin Script
Pins a script:
driver.pin_script("Script to pin") #Pins a script
#Default options:
script_key=None Print Page
Prints the page:
driver.print_page() #Prints the page
#Default options:
print_options=NoneRefresh Page
Refreshes the webpage:
driver.refresh() #Refreshes the active webpageRemove All Credentials
Removes all credentials:
driver.remove_all_credentials() #Removes all credentialsRemove Credential
Removes credential by ID:
driver.remove_credential("credentialID") #Removes credential by idRemove Virtual Authenticator
Removes virtual authenticator:
driver.remove_virtual_authenticator() #Removes virtual authenticatorSet Page Load Time
Sets max page load time in seconds:
driver.set_page_load_timeout(5) #Sets the max page load timeout to 5 secondsSet Script Load Time
Sets max script load time in seconds:
driver.set_script_timeout(5) #Sets the max script load timeout to 5 secondsSet User Verified
Sets user verified:
driver.set_user_verified(True) #Sets whether the authenticator will simulate success or fail on user verificationSet Window Position
Sets window position in pixels:
driver.set_window_position(0,0) #Puts top left corner of browser to top left corner of screen with active window handle
#Default options:
windowHandle="current"
driver.set_window_position(0,0,otherWindowHandle) #Puts top left corner of browser to top left corner of screen with any window handleSet Window Size
Sets window size:
driver.set_window_size(1920,1080) #Sets window size to 9020px * 1080px on current window handle
#Default options:
windowHandle="current"
driver.set_window_size(1920,1080,otherWindowHandle) #Sets window size to 9020px * 1080px on other window handleStart Client
Starts client:
driver.start_client() #Starts clientStart Session
Starts session:
driver.start_session(browserCapabilities) #Starts session with browser capabilitiesStop Client
Stops client:
driver.stop_client() #Stops clientUnpin Script By Key
Unpins script key:
driver.unpin("scriptKey") #Unpins script by keyLast updated