Selenium with Python¶
- Author:
- License:
This document is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Note
This is not an official documentation. If you would like to contribute to this documentation, you can fork this project in GitHub and send pull requests. You can also send your feedback to my email: baiju.m.mail AT gmail DOT com. So far 60+ community members have contributed to this project (See the closed pull requests). I encourage contributors to add more sections and make it an awesome documentation! If you know any translation of this document, please send a PR to update the below list.
Translations:
- 1. Installation
- 2. Getting Started
- 3. Navigating
- 4. Locating Elements
- 5. Waits
- 6. Page Objects
- 7. WebDriver API
- 7.1. Exceptions
ElementClickInterceptedException
ElementNotInteractableException
ElementNotSelectableException
ElementNotVisibleException
ImeActivationFailedException
ImeNotAvailableException
InsecureCertificateException
InvalidArgumentException
InvalidCookieDomainException
InvalidCoordinatesException
InvalidElementStateException
InvalidSelectorException
InvalidSessionIdException
InvalidSwitchToTargetException
JavascriptException
MoveTargetOutOfBoundsException
NoAlertPresentException
NoSuchAttributeException
NoSuchCookieException
NoSuchDriverException
NoSuchElementException
NoSuchFrameException
NoSuchShadowRootException
NoSuchWindowException
ScreenshotException
SessionNotCreatedException
StaleElementReferenceException
TimeoutException
UnableToSetCookieException
UnexpectedAlertPresentException
UnexpectedTagNameException
UnknownMethodException
WebDriverException
- 7.2. Action Chains
ActionChains
ActionChains.__init__()
ActionChains.click()
ActionChains.click_and_hold()
ActionChains.context_click()
ActionChains.double_click()
ActionChains.drag_and_drop()
ActionChains.drag_and_drop_by_offset()
ActionChains.key_down()
ActionChains.key_up()
ActionChains.move_by_offset()
ActionChains.move_to_element()
ActionChains.move_to_element_with_offset()
ActionChains.pause()
ActionChains.perform()
ActionChains.release()
ActionChains.reset_actions()
ActionChains.scroll_by_amount()
ActionChains.scroll_from_origin()
ActionChains.scroll_to_element()
ActionChains.send_keys()
ActionChains.send_keys_to_element()
- 7.3. Alerts
- 7.4. Special Keys
Keys
Keys.ADD
Keys.ALT
Keys.ARROW_DOWN
Keys.ARROW_LEFT
Keys.ARROW_RIGHT
Keys.ARROW_UP
Keys.BACKSPACE
Keys.BACK_SPACE
Keys.CANCEL
Keys.CLEAR
Keys.COMMAND
Keys.CONTROL
Keys.DECIMAL
Keys.DELETE
Keys.DIVIDE
Keys.DOWN
Keys.END
Keys.ENTER
Keys.EQUALS
Keys.ESCAPE
Keys.F1
Keys.F10
Keys.F11
Keys.F12
Keys.F2
Keys.F3
Keys.F4
Keys.F5
Keys.F6
Keys.F7
Keys.F8
Keys.F9
Keys.HELP
Keys.HOME
Keys.INSERT
Keys.LEFT
Keys.LEFT_ALT
Keys.LEFT_CONTROL
Keys.LEFT_SHIFT
Keys.META
Keys.MULTIPLY
Keys.NULL
Keys.NUMPAD0
Keys.NUMPAD1
Keys.NUMPAD2
Keys.NUMPAD3
Keys.NUMPAD4
Keys.NUMPAD5
Keys.NUMPAD6
Keys.NUMPAD7
Keys.NUMPAD8
Keys.NUMPAD9
Keys.PAGE_DOWN
Keys.PAGE_UP
Keys.PAUSE
Keys.RETURN
Keys.RIGHT
Keys.SEMICOLON
Keys.SEPARATOR
Keys.SHIFT
Keys.SPACE
Keys.SUBTRACT
Keys.TAB
Keys.UP
Keys.ZENKAKU_HANKAKU
- 7.5. Locate elements By
- 7.6. Desired Capabilities
DesiredCapabilities
DesiredCapabilities.CHROME
DesiredCapabilities.EDGE
DesiredCapabilities.FIREFOX
DesiredCapabilities.HTMLUNIT
DesiredCapabilities.HTMLUNITWITHJS
DesiredCapabilities.INTERNETEXPLORER
DesiredCapabilities.IPAD
DesiredCapabilities.IPHONE
DesiredCapabilities.SAFARI
DesiredCapabilities.WEBKITGTK
DesiredCapabilities.WPEWEBKIT
- 7.7. Proxy
Proxy
Proxy.__init__()
Proxy.to_capabilities()
Proxy.auto_detect
Proxy.autodetect
Proxy.ftpProxy
Proxy.ftp_proxy
Proxy.httpProxy
Proxy.http_proxy
Proxy.noProxy
Proxy.no_proxy
Proxy.proxyAutoconfigUrl
Proxy.proxyType
Proxy.proxy_autoconfig_url
Proxy.proxy_type
Proxy.socksPassword
Proxy.socksProxy
Proxy.socksUsername
Proxy.socksVersion
Proxy.socks_password
Proxy.socks_proxy
Proxy.socks_username
Proxy.socks_version
Proxy.sslProxy
Proxy.ssl_proxy
ProxyType
ProxyTypeFactory
- 7.8. Utilities
- 7.9. Service
- 7.10. Application Cache
- 7.11. Firefox WebDriver
WebDriver
WebDriver.__init__()
WebDriver.context()
WebDriver.get_full_page_screenshot_as_base64()
WebDriver.get_full_page_screenshot_as_file()
WebDriver.get_full_page_screenshot_as_png()
WebDriver.install_addon()
WebDriver.quit()
WebDriver.save_full_page_screenshot()
WebDriver.set_context()
WebDriver.uninstall_addon()
WebDriver.CONTEXT_CHROME
WebDriver.CONTEXT_CONTENT
- 7.12. Firefox WebDriver Options
- 7.13. Firefox WebDriver Profile
AddonFormatError
FirefoxProfile
FirefoxProfile.__init__()
FirefoxProfile.add_extension()
FirefoxProfile.set_preference()
FirefoxProfile.update_preferences()
FirefoxProfile.DEFAULT_PREFERENCES
FirefoxProfile.accept_untrusted_certs
FirefoxProfile.assume_untrusted_cert_issuer
FirefoxProfile.encoded
FirefoxProfile.path
FirefoxProfile.port
- 7.14. Firefox WebDriver Binary
- 7.15. Firefox WebDriver Extension Connection
- 7.16. Chrome WebDriver
- 7.17. Chrome WebDriver Options
- 7.18. Chrome WebDriver Service
- 7.19. Remote WebDriver
BaseWebDriver
WebDriver
WebDriver.__init__()
WebDriver.add_cookie()
WebDriver.add_credential()
WebDriver.add_virtual_authenticator()
WebDriver.back()
WebDriver.bidi_connection()
WebDriver.close()
WebDriver.create_web_element()
WebDriver.delete_all_cookies()
WebDriver.delete_cookie()
WebDriver.delete_downloadable_files()
WebDriver.download_file()
WebDriver.execute()
WebDriver.execute_async_script()
WebDriver.execute_script()
WebDriver.file_detector_context()
WebDriver.find_element()
WebDriver.find_elements()
WebDriver.forward()
WebDriver.fullscreen_window()
WebDriver.get()
WebDriver.get_cookie()
WebDriver.get_cookies()
WebDriver.get_credentials()
WebDriver.get_downloadable_files()
WebDriver.get_log()
WebDriver.get_pinned_scripts()
WebDriver.get_screenshot_as_base64()
WebDriver.get_screenshot_as_file()
WebDriver.get_screenshot_as_png()
WebDriver.get_window_position()
WebDriver.get_window_rect()
WebDriver.get_window_size()
WebDriver.implicitly_wait()
WebDriver.maximize_window()
WebDriver.minimize_window()
WebDriver.pin_script()
WebDriver.print_page()
WebDriver.quit()
WebDriver.refresh()
WebDriver.remove_all_credentials()
WebDriver.remove_credential()
WebDriver.remove_virtual_authenticator()
WebDriver.save_screenshot()
WebDriver.set_page_load_timeout()
WebDriver.set_script_timeout()
WebDriver.set_user_verified()
WebDriver.set_window_position()
WebDriver.set_window_rect()
WebDriver.set_window_size()
WebDriver.start_client()
WebDriver.start_session()
WebDriver.stop_client()
WebDriver.unpin()
WebDriver.capabilities
WebDriver.current_url
WebDriver.current_window_handle
WebDriver.file_detector
WebDriver.log_types
WebDriver.mobile
WebDriver.name
WebDriver.orientation
WebDriver.page_source
WebDriver.switch_to
WebDriver.timeouts
WebDriver.title
WebDriver.virtual_authenticator_id
WebDriver.window_handles
create_matches()
get_remote_connection()
import_cdp()
- 7.20. Remote WebDriver WebElement
BaseWebElement
WebElement
WebElement.__init__()
WebElement.clear()
WebElement.click()
WebElement.find_element()
WebElement.find_elements()
WebElement.get_attribute()
WebElement.get_dom_attribute()
WebElement.get_property()
WebElement.is_displayed()
WebElement.is_enabled()
WebElement.is_selected()
WebElement.screenshot()
WebElement.send_keys()
WebElement.submit()
WebElement.value_of_css_property()
WebElement.accessible_name
WebElement.aria_role
WebElement.id
WebElement.location
WebElement.location_once_scrolled_into_view
WebElement.parent
WebElement.rect
WebElement.screenshot_as_base64
WebElement.screenshot_as_png
WebElement.shadow_root
WebElement.size
WebElement.tag_name
WebElement.text
- 7.21. Remote WebDriver Command
Command
Command.ADD_COOKIE
Command.ADD_CREDENTIAL
Command.ADD_VIRTUAL_AUTHENTICATOR
Command.CLEAR_ELEMENT
Command.CLICK_ELEMENT
Command.CLOSE
Command.CONTEXT_HANDLES
Command.CURRENT_CONTEXT_HANDLE
Command.DELETE_ALL_COOKIES
Command.DELETE_COOKIE
Command.DELETE_DOWNLOADABLE_FILES
Command.DELETE_SESSION
Command.DOWNLOAD_FILE
Command.ELEMENT_SCREENSHOT
Command.EXECUTE_ASYNC_SCRIPT
Command.FIND_CHILD_ELEMENT
Command.FIND_CHILD_ELEMENTS
Command.FIND_ELEMENT
Command.FIND_ELEMENTS
Command.FIND_ELEMENTS_FROM_SHADOW_ROOT
Command.FIND_ELEMENT_FROM_SHADOW_ROOT
Command.FULLSCREEN_WINDOW
Command.GET
Command.GET_ALL_COOKIES
Command.GET_AVAILABLE_LOG_TYPES
Command.GET_COOKIE
Command.GET_CREDENTIALS
Command.GET_CURRENT_URL
Command.GET_DOWNLOADABLE_FILES
Command.GET_ELEMENT_ARIA_LABEL
Command.GET_ELEMENT_ARIA_ROLE
Command.GET_ELEMENT_ATTRIBUTE
Command.GET_ELEMENT_PROPERTY
Command.GET_ELEMENT_RECT
Command.GET_ELEMENT_TAG_NAME
Command.GET_ELEMENT_TEXT
Command.GET_ELEMENT_VALUE_OF_CSS_PROPERTY
Command.GET_LOG
Command.GET_NETWORK_CONNECTION
Command.GET_PAGE_SOURCE
Command.GET_SCREEN_ORIENTATION
Command.GET_SHADOW_ROOT
Command.GET_TIMEOUTS
Command.GET_TITLE
Command.GET_WINDOW_RECT
Command.GO_BACK
Command.GO_FORWARD
Command.IS_ELEMENT_ENABLED
Command.IS_ELEMENT_SELECTED
Command.MINIMIZE_WINDOW
Command.NEW_SESSION
Command.NEW_WINDOW
Command.PRINT_PAGE
Command.QUIT
Command.REFRESH
Command.REMOVE_ALL_CREDENTIALS
Command.REMOVE_CREDENTIAL
Command.REMOVE_VIRTUAL_AUTHENTICATOR
Command.SCREENSHOT
Command.SEND_KEYS_TO_ELEMENT
Command.SET_NETWORK_CONNECTION
Command.SET_SCREEN_ORIENTATION
Command.SET_TIMEOUTS
Command.SET_USER_VERIFIED
Command.SET_WINDOW_RECT
Command.SWITCH_TO_CONTEXT
Command.SWITCH_TO_FRAME
Command.SWITCH_TO_PARENT_FRAME
Command.SWITCH_TO_WINDOW
Command.UPLOAD_FILE
Command.W3C_ACCEPT_ALERT
Command.W3C_ACTIONS
Command.W3C_CLEAR_ACTIONS
Command.W3C_DISMISS_ALERT
Command.W3C_EXECUTE_SCRIPT
Command.W3C_EXECUTE_SCRIPT_ASYNC
Command.W3C_GET_ACTIVE_ELEMENT
Command.W3C_GET_ALERT_TEXT
Command.W3C_GET_CURRENT_WINDOW_HANDLE
Command.W3C_GET_WINDOW_HANDLES
Command.W3C_MAXIMIZE_WINDOW
Command.W3C_SET_ALERT_VALUE
- 7.22. Remote WebDriver Error Handler
ErrorCode
ErrorCode.ELEMENT_CLICK_INTERCEPTED
ErrorCode.ELEMENT_IS_NOT_SELECTABLE
ErrorCode.ELEMENT_NOT_INTERACTABLE
ErrorCode.ELEMENT_NOT_VISIBLE
ErrorCode.IME_ENGINE_ACTIVATION_FAILED
ErrorCode.IME_NOT_AVAILABLE
ErrorCode.INSECURE_CERTIFICATE
ErrorCode.INVALID_ARGUMENT
ErrorCode.INVALID_COOKIE_DOMAIN
ErrorCode.INVALID_COORDINATES
ErrorCode.INVALID_ELEMENT_COORDINATES
ErrorCode.INVALID_ELEMENT_STATE
ErrorCode.INVALID_SELECTOR
ErrorCode.INVALID_SESSION_ID
ErrorCode.INVALID_XPATH_SELECTOR
ErrorCode.INVALID_XPATH_SELECTOR_RETURN_TYPER
ErrorCode.JAVASCRIPT_ERROR
ErrorCode.METHOD_NOT_ALLOWED
ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS
ErrorCode.NO_ALERT_OPEN
ErrorCode.NO_SUCH_COOKIE
ErrorCode.NO_SUCH_ELEMENT
ErrorCode.NO_SUCH_FRAME
ErrorCode.NO_SUCH_SHADOW_ROOT
ErrorCode.NO_SUCH_WINDOW
ErrorCode.SCRIPT_TIMEOUT
ErrorCode.SESSION_NOT_CREATED
ErrorCode.STALE_ELEMENT_REFERENCE
ErrorCode.SUCCESS
ErrorCode.TIMEOUT
ErrorCode.UNABLE_TO_CAPTURE_SCREEN
ErrorCode.UNABLE_TO_SET_COOKIE
ErrorCode.UNEXPECTED_ALERT_OPEN
ErrorCode.UNKNOWN_COMMAND
ErrorCode.UNKNOWN_ERROR
ErrorCode.UNKNOWN_METHOD
ErrorCode.XPATH_LOOKUP_ERROR
ErrorHandler
ExceptionMapping
ExceptionMapping.ELEMENT_CLICK_INTERCEPTED
ExceptionMapping.ELEMENT_IS_NOT_SELECTABLE
ExceptionMapping.ELEMENT_NOT_INTERACTABLE
ExceptionMapping.ELEMENT_NOT_VISIBLE
ExceptionMapping.IME_ENGINE_ACTIVATION_FAILED
ExceptionMapping.IME_NOT_AVAILABLE
ExceptionMapping.INSECURE_CERTIFICATE
ExceptionMapping.INVALID_ARGUMENT
ExceptionMapping.INVALID_COOKIE_DOMAIN
ExceptionMapping.INVALID_COORDINATES
ExceptionMapping.INVALID_ELEMENT_STATE
ExceptionMapping.INVALID_SELECTOR
ExceptionMapping.INVALID_SESSION_ID
ExceptionMapping.INVALID_XPATH_SELECTOR
ExceptionMapping.INVALID_XPATH_SELECTOR_RETURN_TYPER
ExceptionMapping.JAVASCRIPT_ERROR
ExceptionMapping.MOVE_TARGET_OUT_OF_BOUNDS
ExceptionMapping.NO_ALERT_OPEN
ExceptionMapping.NO_SUCH_COOKIE
ExceptionMapping.NO_SUCH_ELEMENT
ExceptionMapping.NO_SUCH_FRAME
ExceptionMapping.NO_SUCH_SHADOW_ROOT
ExceptionMapping.NO_SUCH_WINDOW
ExceptionMapping.SCRIPT_TIMEOUT
ExceptionMapping.SESSION_NOT_CREATED
ExceptionMapping.STALE_ELEMENT_REFERENCE
ExceptionMapping.TIMEOUT
ExceptionMapping.UNABLE_TO_CAPTURE_SCREEN
ExceptionMapping.UNABLE_TO_SET_COOKIE
ExceptionMapping.UNEXPECTED_ALERT_OPEN
ExceptionMapping.UNKNOWN_ERROR
ExceptionMapping.UNKNOWN_METHOD
- 7.23. Remote WebDriver Mobile
- 7.24. Remote WebDriver Remote Connection
RemoteConnection
RemoteConnection.__init__()
RemoteConnection.close()
RemoteConnection.execute()
RemoteConnection.get_certificate_bundle_path()
RemoteConnection.get_remote_connection_headers()
RemoteConnection.get_timeout()
RemoteConnection.reset_timeout()
RemoteConnection.set_certificate_bundle_path()
RemoteConnection.set_timeout()
RemoteConnection.browser_name
- 7.25. Remote WebDriver Utils
- 7.26. Internet Explorer WebDriver
- 7.27. Safari WebDriver
- 7.28. Safari WebDriver Service
- 7.29. Select Support
- 7.30. Wait Support
- 7.31. Color Support
- 7.32. Event Firing WebDriver Support
EventFiringWebDriver
EventFiringWebDriver.__init__()
EventFiringWebDriver.back()
EventFiringWebDriver.close()
EventFiringWebDriver.execute_async_script()
EventFiringWebDriver.execute_script()
EventFiringWebDriver.find_element()
EventFiringWebDriver.find_elements()
EventFiringWebDriver.forward()
EventFiringWebDriver.get()
EventFiringWebDriver.quit()
EventFiringWebDriver.wrapped_driver
EventFiringWebElement
- 7.33. Abstract Event Listener Support
AbstractEventListener
AbstractEventListener.after_change_value_of()
AbstractEventListener.after_click()
AbstractEventListener.after_close()
AbstractEventListener.after_execute_script()
AbstractEventListener.after_find()
AbstractEventListener.after_navigate_back()
AbstractEventListener.after_navigate_forward()
AbstractEventListener.after_navigate_to()
AbstractEventListener.after_quit()
AbstractEventListener.before_change_value_of()
AbstractEventListener.before_click()
AbstractEventListener.before_close()
AbstractEventListener.before_execute_script()
AbstractEventListener.before_find()
AbstractEventListener.before_navigate_back()
AbstractEventListener.before_navigate_forward()
AbstractEventListener.before_navigate_to()
AbstractEventListener.before_quit()
AbstractEventListener.on_exception()
- 7.34. Expected conditions Support
alert_is_present()
all_of()
any_of()
element_attribute_to_include()
element_located_selection_state_to_be()
element_located_to_be_selected()
element_selection_state_to_be()
element_to_be_clickable()
element_to_be_selected()
frame_to_be_available_and_switch_to_it()
invisibility_of_element()
invisibility_of_element_located()
new_window_is_opened()
none_of()
number_of_windows_to_be()
presence_of_all_elements_located()
presence_of_element_located()
staleness_of()
text_to_be_present_in_element()
text_to_be_present_in_element_attribute()
text_to_be_present_in_element_value()
title_contains()
title_is()
url_changes()
url_contains()
url_matches()
url_to_be()
visibility_of()
visibility_of_all_elements_located()
visibility_of_any_elements_located()
visibility_of_element_located()
- 7.1. Exceptions
- 8. Appendix: Frequently Asked Questions
- 8.1. How to use ChromeDriver ?
- 8.2. Does Selenium 2 support XPath 2.0 ?
- 8.3. How to scroll down to the bottom of a page ?
- 8.4. How to auto save files using custom Firefox profile ?
- 8.5. How to upload files into file inputs ?
- 8.6. How to use firebug with Firefox ?
- 8.7. How to take screenshot of the current window ?