Selenium with Python¶
- Author:
- License:
This document is licensed under aCreative Commons Attribution-ShareAlike 4.0 International License.
Note
This is not an official documentation. If you would like to contribute tothis documentation, you canfork this project in GitHub and send pullrequests. You can also sendyour feedback to my email: baiju.m.mail AT gmail DOT com. So far 60+community members have contributed to this project (See the closed pullrequests). I encourage contributors to add more sections and make it anawesome documentation! If you know any translation of this document, pleasesend 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
ElementClickInterceptedExceptionElementNotInteractableExceptionElementNotSelectableExceptionElementNotVisibleExceptionImeActivationFailedExceptionImeNotAvailableExceptionInsecureCertificateExceptionInvalidArgumentExceptionInvalidCookieDomainExceptionInvalidCoordinatesExceptionInvalidElementStateExceptionInvalidSelectorExceptionInvalidSessionIdExceptionInvalidSwitchToTargetExceptionJavascriptExceptionMoveTargetOutOfBoundsExceptionNoAlertPresentExceptionNoSuchAttributeExceptionNoSuchCookieExceptionNoSuchDriverExceptionNoSuchElementExceptionNoSuchFrameExceptionNoSuchShadowRootExceptionNoSuchWindowExceptionScreenshotExceptionSessionNotCreatedExceptionStaleElementReferenceExceptionTimeoutExceptionUnableToSetCookieExceptionUnexpectedAlertPresentExceptionUnexpectedTagNameExceptionUnknownMethodExceptionWebDriverException
- 7.2. Action Chains
ActionChainsActionChains.__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
KeysKeys.ADDKeys.ALTKeys.ARROW_DOWNKeys.ARROW_LEFTKeys.ARROW_RIGHTKeys.ARROW_UPKeys.BACKSPACEKeys.BACK_SPACEKeys.CANCELKeys.CLEARKeys.COMMANDKeys.CONTROLKeys.DECIMALKeys.DELETEKeys.DIVIDEKeys.DOWNKeys.ENDKeys.ENTERKeys.EQUALSKeys.ESCAPEKeys.F1Keys.F10Keys.F11Keys.F12Keys.F2Keys.F3Keys.F4Keys.F5Keys.F6Keys.F7Keys.F8Keys.F9Keys.HELPKeys.HOMEKeys.INSERTKeys.LEFTKeys.LEFT_ALTKeys.LEFT_CONTROLKeys.LEFT_SHIFTKeys.METAKeys.MULTIPLYKeys.NULLKeys.NUMPAD0Keys.NUMPAD1Keys.NUMPAD2Keys.NUMPAD3Keys.NUMPAD4Keys.NUMPAD5Keys.NUMPAD6Keys.NUMPAD7Keys.NUMPAD8Keys.NUMPAD9Keys.PAGE_DOWNKeys.PAGE_UPKeys.PAUSEKeys.RETURNKeys.RIGHTKeys.SEMICOLONKeys.SEPARATORKeys.SHIFTKeys.SPACEKeys.SUBTRACTKeys.TABKeys.UPKeys.ZENKAKU_HANKAKU
- 7.5. Locate elements By
- 7.6. Desired Capabilities
DesiredCapabilitiesDesiredCapabilities.CHROMEDesiredCapabilities.EDGEDesiredCapabilities.FIREFOXDesiredCapabilities.HTMLUNITDesiredCapabilities.HTMLUNITWITHJSDesiredCapabilities.INTERNETEXPLORERDesiredCapabilities.IPADDesiredCapabilities.IPHONEDesiredCapabilities.SAFARIDesiredCapabilities.WEBKITGTKDesiredCapabilities.WPEWEBKIT
- 7.7. Proxy
ProxyProxy.__init__()Proxy.to_capabilities()Proxy.auto_detectProxy.autodetectProxy.ftpProxyProxy.ftp_proxyProxy.httpProxyProxy.http_proxyProxy.noProxyProxy.no_proxyProxy.proxyAutoconfigUrlProxy.proxyTypeProxy.proxy_autoconfig_urlProxy.proxy_typeProxy.socksPasswordProxy.socksProxyProxy.socksUsernameProxy.socksVersionProxy.socks_passwordProxy.socks_proxyProxy.socks_usernameProxy.socks_versionProxy.sslProxyProxy.ssl_proxy
ProxyTypeProxyTypeFactory
- 7.8. Utilities
- 7.9. Service
- 7.10. Application Cache
- 7.11. Firefox WebDriver
WebDriverWebDriver.__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_CHROMEWebDriver.CONTEXT_CONTENT
- 7.12. Firefox WebDriver Options
- 7.13. Firefox WebDriver Profile
- 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
BaseWebDriverWebDriverWebDriver.__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.capabilitiesWebDriver.current_urlWebDriver.current_window_handleWebDriver.file_detectorWebDriver.log_typesWebDriver.mobileWebDriver.nameWebDriver.orientationWebDriver.page_sourceWebDriver.switch_toWebDriver.timeoutsWebDriver.titleWebDriver.virtual_authenticator_idWebDriver.window_handles
create_matches()get_remote_connection()import_cdp()
- 7.20. Remote WebDriver WebElement
BaseWebElementWebElementWebElement.__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_nameWebElement.aria_roleWebElement.idWebElement.locationWebElement.location_once_scrolled_into_viewWebElement.parentWebElement.rectWebElement.screenshot_as_base64WebElement.screenshot_as_pngWebElement.shadow_rootWebElement.sizeWebElement.tag_nameWebElement.text
- 7.21. Remote WebDriver Command
CommandCommand.ADD_COOKIECommand.ADD_CREDENTIALCommand.ADD_VIRTUAL_AUTHENTICATORCommand.CLEAR_ELEMENTCommand.CLICK_ELEMENTCommand.CLOSECommand.CONTEXT_HANDLESCommand.CURRENT_CONTEXT_HANDLECommand.DELETE_ALL_COOKIESCommand.DELETE_COOKIECommand.DELETE_DOWNLOADABLE_FILESCommand.DELETE_SESSIONCommand.DOWNLOAD_FILECommand.ELEMENT_SCREENSHOTCommand.EXECUTE_ASYNC_SCRIPTCommand.FIND_CHILD_ELEMENTCommand.FIND_CHILD_ELEMENTSCommand.FIND_ELEMENTCommand.FIND_ELEMENTSCommand.FIND_ELEMENTS_FROM_SHADOW_ROOTCommand.FIND_ELEMENT_FROM_SHADOW_ROOTCommand.FULLSCREEN_WINDOWCommand.GETCommand.GET_ALL_COOKIESCommand.GET_AVAILABLE_LOG_TYPESCommand.GET_COOKIECommand.GET_CREDENTIALSCommand.GET_CURRENT_URLCommand.GET_DOWNLOADABLE_FILESCommand.GET_ELEMENT_ARIA_LABELCommand.GET_ELEMENT_ARIA_ROLECommand.GET_ELEMENT_ATTRIBUTECommand.GET_ELEMENT_PROPERTYCommand.GET_ELEMENT_RECTCommand.GET_ELEMENT_TAG_NAMECommand.GET_ELEMENT_TEXTCommand.GET_ELEMENT_VALUE_OF_CSS_PROPERTYCommand.GET_LOGCommand.GET_NETWORK_CONNECTIONCommand.GET_PAGE_SOURCECommand.GET_SCREEN_ORIENTATIONCommand.GET_SHADOW_ROOTCommand.GET_TIMEOUTSCommand.GET_TITLECommand.GET_WINDOW_RECTCommand.GO_BACKCommand.GO_FORWARDCommand.IS_ELEMENT_ENABLEDCommand.IS_ELEMENT_SELECTEDCommand.MINIMIZE_WINDOWCommand.NEW_SESSIONCommand.NEW_WINDOWCommand.PRINT_PAGECommand.QUITCommand.REFRESHCommand.REMOVE_ALL_CREDENTIALSCommand.REMOVE_CREDENTIALCommand.REMOVE_VIRTUAL_AUTHENTICATORCommand.SCREENSHOTCommand.SEND_KEYS_TO_ELEMENTCommand.SET_NETWORK_CONNECTIONCommand.SET_SCREEN_ORIENTATIONCommand.SET_TIMEOUTSCommand.SET_USER_VERIFIEDCommand.SET_WINDOW_RECTCommand.SWITCH_TO_CONTEXTCommand.SWITCH_TO_FRAMECommand.SWITCH_TO_PARENT_FRAMECommand.SWITCH_TO_WINDOWCommand.UPLOAD_FILECommand.W3C_ACCEPT_ALERTCommand.W3C_ACTIONSCommand.W3C_CLEAR_ACTIONSCommand.W3C_DISMISS_ALERTCommand.W3C_EXECUTE_SCRIPTCommand.W3C_EXECUTE_SCRIPT_ASYNCCommand.W3C_GET_ACTIVE_ELEMENTCommand.W3C_GET_ALERT_TEXTCommand.W3C_GET_CURRENT_WINDOW_HANDLECommand.W3C_GET_WINDOW_HANDLESCommand.W3C_MAXIMIZE_WINDOWCommand.W3C_SET_ALERT_VALUE
- 7.22. Remote WebDriver Error Handler
ErrorCodeErrorCode.ELEMENT_CLICK_INTERCEPTEDErrorCode.ELEMENT_IS_NOT_SELECTABLEErrorCode.ELEMENT_NOT_INTERACTABLEErrorCode.ELEMENT_NOT_VISIBLEErrorCode.IME_ENGINE_ACTIVATION_FAILEDErrorCode.IME_NOT_AVAILABLEErrorCode.INSECURE_CERTIFICATEErrorCode.INVALID_ARGUMENTErrorCode.INVALID_COOKIE_DOMAINErrorCode.INVALID_COORDINATESErrorCode.INVALID_ELEMENT_COORDINATESErrorCode.INVALID_ELEMENT_STATEErrorCode.INVALID_SELECTORErrorCode.INVALID_SESSION_IDErrorCode.INVALID_XPATH_SELECTORErrorCode.INVALID_XPATH_SELECTOR_RETURN_TYPERErrorCode.JAVASCRIPT_ERRORErrorCode.METHOD_NOT_ALLOWEDErrorCode.MOVE_TARGET_OUT_OF_BOUNDSErrorCode.NO_ALERT_OPENErrorCode.NO_SUCH_COOKIEErrorCode.NO_SUCH_ELEMENTErrorCode.NO_SUCH_FRAMEErrorCode.NO_SUCH_SHADOW_ROOTErrorCode.NO_SUCH_WINDOWErrorCode.SCRIPT_TIMEOUTErrorCode.SESSION_NOT_CREATEDErrorCode.STALE_ELEMENT_REFERENCEErrorCode.SUCCESSErrorCode.TIMEOUTErrorCode.UNABLE_TO_CAPTURE_SCREENErrorCode.UNABLE_TO_SET_COOKIEErrorCode.UNEXPECTED_ALERT_OPENErrorCode.UNKNOWN_COMMANDErrorCode.UNKNOWN_ERRORErrorCode.UNKNOWN_METHODErrorCode.XPATH_LOOKUP_ERROR
ErrorHandlerExceptionMappingExceptionMapping.ELEMENT_CLICK_INTERCEPTEDExceptionMapping.ELEMENT_IS_NOT_SELECTABLEExceptionMapping.ELEMENT_NOT_INTERACTABLEExceptionMapping.ELEMENT_NOT_VISIBLEExceptionMapping.IME_ENGINE_ACTIVATION_FAILEDExceptionMapping.IME_NOT_AVAILABLEExceptionMapping.INSECURE_CERTIFICATEExceptionMapping.INVALID_ARGUMENTExceptionMapping.INVALID_COOKIE_DOMAINExceptionMapping.INVALID_COORDINATESExceptionMapping.INVALID_ELEMENT_STATEExceptionMapping.INVALID_SELECTORExceptionMapping.INVALID_SESSION_IDExceptionMapping.INVALID_XPATH_SELECTORExceptionMapping.INVALID_XPATH_SELECTOR_RETURN_TYPERExceptionMapping.JAVASCRIPT_ERRORExceptionMapping.MOVE_TARGET_OUT_OF_BOUNDSExceptionMapping.NO_ALERT_OPENExceptionMapping.NO_SUCH_COOKIEExceptionMapping.NO_SUCH_ELEMENTExceptionMapping.NO_SUCH_FRAMEExceptionMapping.NO_SUCH_SHADOW_ROOTExceptionMapping.NO_SUCH_WINDOWExceptionMapping.SCRIPT_TIMEOUTExceptionMapping.SESSION_NOT_CREATEDExceptionMapping.STALE_ELEMENT_REFERENCEExceptionMapping.TIMEOUTExceptionMapping.UNABLE_TO_CAPTURE_SCREENExceptionMapping.UNABLE_TO_SET_COOKIEExceptionMapping.UNEXPECTED_ALERT_OPENExceptionMapping.UNKNOWN_ERRORExceptionMapping.UNKNOWN_METHOD
- 7.23. Remote WebDriver Mobile
- 7.24. Remote WebDriver Remote Connection
RemoteConnectionRemoteConnection.__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
EventFiringWebDriverEventFiringWebDriver.__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
AbstractEventListenerAbstractEventListener.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 ?
