王成军
Selenium 是一套完整的web应用程序测试系统,包含了
Selenium的核心Selenium Core基于JsUnit,完全由JavaScript编写,因此可以用于任何支持JavaScript的浏览器上。selenium可以模拟真实浏览器,自动化测试工具,支持多种浏览器,爬虫中主要用来解决JavaScript渲染问题。https://www.cnblogs.com/zhaof/p/6953241.html
上面我们知道了selenium支持很多的浏览器,但是如果想要声明并调用浏览器则需要: https://pypi.org/project/selenium/
pip install -U selenium
Collecting selenium Downloading selenium-4.15.2-py3-none-any.whl (10.2 MB) |████████████████████████████████| 10.2 MB 857 kB/s eta 0:00:01 Collecting trio~=0.17 Downloading trio-0.23.1-py3-none-any.whl (448 kB) |████████████████████████████████| 448 kB 3.2 MB/s eta 0:00:01 Requirement already satisfied: certifi>=2021.10.8 in /opt/anaconda3/lib/python3.9/site-packages (from selenium) (2021.10.8) Requirement already satisfied: urllib3[socks]<3,>=1.26 in /opt/anaconda3/lib/python3.9/site-packages (from selenium) (1.26.7) Collecting trio-websocket~=0.9 Downloading trio_websocket-0.11.1-py3-none-any.whl (17 kB) Collecting sniffio>=1.3.0 Downloading sniffio-1.3.0-py3-none-any.whl (10 kB) Collecting exceptiongroup>=1.0.0rc9 Downloading exceptiongroup-1.1.3-py3-none-any.whl (14 kB) Collecting outcome Downloading outcome-1.3.0.post0-py2.py3-none-any.whl (10 kB) Requirement already satisfied: idna in /opt/anaconda3/lib/python3.9/site-packages (from trio~=0.17->selenium) (3.2) Requirement already satisfied: attrs>=20.1.0 in /opt/anaconda3/lib/python3.9/site-packages (from trio~=0.17->selenium) (21.2.0) Requirement already satisfied: sortedcontainers in /opt/anaconda3/lib/python3.9/site-packages (from trio~=0.17->selenium) (2.4.0) Collecting wsproto>=0.14 Downloading wsproto-1.2.0-py3-none-any.whl (24 kB) Requirement already satisfied: PySocks!=1.5.7,<2.0,>=1.5.6 in /opt/anaconda3/lib/python3.9/site-packages (from urllib3[socks]<3,>=1.26->selenium) (1.7.1) Collecting h11<1,>=0.9.0 Downloading h11-0.14.0-py3-none-any.whl (58 kB) |████████████████████████████████| 58 kB 3.9 MB/s eta 0:00:011 Installing collected packages: sniffio, outcome, h11, exceptiongroup, wsproto, trio, trio-websocket, selenium Attempting uninstall: sniffio Found existing installation: sniffio 1.2.0 Uninstalling sniffio-1.2.0: Successfully uninstalled sniffio-1.2.0 Successfully installed exceptiongroup-1.1.3 h11-0.14.0 outcome-1.3.0.post0 selenium-4.15.2 sniffio-1.3.0 trio-0.23.1 trio-websocket-0.11.1 wsproto-1.2.0 Note: you may need to restart the kernel to use updated packages.
from selenium import webdriver
help(webdriver)
Help on package selenium.webdriver in selenium: NAME selenium.webdriver DESCRIPTION # Licensed to the Software Freedom Conservancy (SFC) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The SFC licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. PACKAGE CONTENTS chrome (package) chromium (package) common (package) edge (package) firefox (package) ie (package) remote (package) safari (package) support (package) webkitgtk (package) wpewebkit (package) CLASSES builtins.object selenium.webdriver.common.action_chains.ActionChains selenium.webdriver.common.desired_capabilities.DesiredCapabilities selenium.webdriver.common.keys.Keys selenium.webdriver.common.proxy.Proxy selenium.webdriver.firefox.firefox_profile.FirefoxProfile selenium.webdriver.chromium.options.ChromiumOptions(selenium.webdriver.common.options.ArgOptions) selenium.webdriver.chrome.options.Options selenium.webdriver.edge.options.Options selenium.webdriver.chromium.service.ChromiumService(selenium.webdriver.common.service.Service) selenium.webdriver.chrome.service.Service selenium.webdriver.edge.service.Service selenium.webdriver.chromium.webdriver.ChromiumDriver(selenium.webdriver.remote.webdriver.WebDriver) selenium.webdriver.chrome.webdriver.WebDriver selenium.webdriver.edge.webdriver.WebDriver selenium.webdriver.common.options.ArgOptions(selenium.webdriver.common.options.BaseOptions) selenium.webdriver.firefox.options.Options selenium.webdriver.ie.options.Options selenium.webdriver.safari.options.Options selenium.webdriver.webkitgtk.options.Options selenium.webdriver.wpewebkit.options.Options selenium.webdriver.common.service.Service(abc.ABC) selenium.webdriver.firefox.service.Service selenium.webdriver.ie.service.Service selenium.webdriver.safari.service.Service selenium.webdriver.webkitgtk.service.Service selenium.webdriver.wpewebkit.service.Service selenium.webdriver.remote.webdriver.BaseWebDriver(builtins.object) selenium.webdriver.remote.webdriver.WebDriver selenium.webdriver.firefox.webdriver.WebDriver selenium.webdriver.ie.webdriver.WebDriver selenium.webdriver.safari.webdriver.WebDriver selenium.webdriver.webkitgtk.webdriver.WebDriver selenium.webdriver.wpewebkit.webdriver.WebDriver class ActionChains(builtins.object) | ActionChains(driver: 'WebDriver', duration: 'int' = 250, devices: 'list[AnyDevice] | None' = None) -> 'None' | | ActionChains are a way to automate low level interactions such as mouse | movements, mouse button actions, key press, and context menu interactions. | This is useful for doing more complex actions like hover over and drag and | drop. | | Generate user actions. | When you call methods for actions on the ActionChains object, | the actions are stored in a queue in the ActionChains object. | When you call perform(), the events are fired in the order they | are queued up. | | ActionChains can be used in a chain pattern:: | | menu = driver.find_element(By.CSS_SELECTOR, ".nav") | hidden_submenu = driver.find_element(By.CSS_SELECTOR, ".nav #submenu1") | | ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform() | | Or actions can be queued up one by one, then performed.:: | | menu = driver.find_element(By.CSS_SELECTOR, ".nav") | hidden_submenu = driver.find_element(By.CSS_SELECTOR, ".nav #submenu1") | | actions = ActionChains(driver) | actions.move_to_element(menu) | actions.click(hidden_submenu) | actions.perform() | | Either way, the actions are performed in the order they are called, one after | another. | | Methods defined here: | | __enter__(self) -> 'ActionChains' | | __exit__(self, _type, _value, _traceback) -> 'None' | | __init__(self, driver: 'WebDriver', duration: 'int' = 250, devices: 'list[AnyDevice] | None' = None) -> 'None' | Creates a new ActionChains. | | :Args: | - driver: The WebDriver instance which performs user actions. | - duration: override the default 250 msecs of DEFAULT_MOVE_DURATION in PointerInput | | click(self, on_element: 'WebElement | None' = None) -> 'ActionChains' | Clicks an element. | | :Args: | - on_element: The element to click. | If None, clicks on current mouse position. | | click_and_hold(self, on_element: 'WebElement | None' = None) -> 'ActionChains' | Holds down the left mouse button on an element. | | :Args: | - on_element: The element to mouse down. | If None, clicks on current mouse position. | | context_click(self, on_element: 'WebElement | None' = None) -> 'ActionChains' | Performs a context-click (right click) on an element. | | :Args: | - on_element: The element to context-click. | If None, clicks on current mouse position. | | double_click(self, on_element: 'WebElement | None' = None) -> 'ActionChains' | Double-clicks an element. | | :Args: | - on_element: The element to double-click. | If None, clicks on current mouse position. | | drag_and_drop(self, source: 'WebElement', target: 'WebElement') -> 'ActionChains' | Holds down the left mouse button on the source element, then moves | to the target element and releases the mouse button. | | :Args: | - source: The element to mouse down. | - target: The element to mouse up. | | drag_and_drop_by_offset(self, source: 'WebElement', xoffset: 'int', yoffset: 'int') -> 'ActionChains' | Holds down the left mouse button on the source element, then moves | to the target offset and releases the mouse button. | | :Args: | - source: The element to mouse down. | - xoffset: X offset to move to. | - yoffset: Y offset to move to. | | key_down(self, value: 'str', element: 'WebElement | None' = None) -> 'ActionChains' | Sends a key press only, without releasing it. Should only be used | with modifier keys (Control, Alt and Shift). | | :Args: | - value: The modifier key to send. Values are defined in `Keys` class. | - element: The element to send keys. | If None, sends a key to current focused element. | | Example, pressing ctrl+c:: | | ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform() | | key_up(self, value: 'str', element: 'WebElement | None' = None) -> 'ActionChains' | Releases a modifier key. | | :Args: | - value: The modifier key to send. Values are defined in Keys class. | - element: The element to send keys. | If None, sends a key to current focused element. | | Example, pressing ctrl+c:: | | ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform() | | move_by_offset(self, xoffset: 'int', yoffset: 'int') -> 'ActionChains' | Moving the mouse to an offset from current mouse position. | | :Args: | - xoffset: X offset to move to, as a positive or negative integer. | - yoffset: Y offset to move to, as a positive or negative integer. | | move_to_element(self, to_element: 'WebElement') -> 'ActionChains' | Moving the mouse to the middle of an element. | | :Args: | - to_element: The WebElement to move to. | | move_to_element_with_offset(self, to_element: 'WebElement', xoffset: 'int', yoffset: 'int') -> 'ActionChains' | Move the mouse by an offset of the specified element. Offsets are | relative to the in-view center point of the element. | | :Args: | - to_element: The WebElement to move to. | - xoffset: X offset to move to, as a positive or negative integer. | - yoffset: Y offset to move to, as a positive or negative integer. | | pause(self, seconds: 'float | int') -> 'ActionChains' | Pause all inputs for the specified duration in seconds. | | perform(self) -> 'None' | Performs all stored actions. | | release(self, on_element: 'WebElement | None' = None) -> 'ActionChains' | Releasing a held mouse button on an element. | | :Args: | - on_element: The element to mouse up. | If None, releases on current mouse position. | | reset_actions(self) -> 'None' | Clears actions that are already stored locally and on the remote | end. | | scroll_by_amount(self, delta_x: 'int', delta_y: 'int') -> 'ActionChains' | Scrolls by provided amounts with the origin in the top left corner | of the viewport. | | :Args: | - delta_x: Distance along X axis to scroll using the wheel. A negative value scrolls left. | - delta_y: Distance along Y axis to scroll using the wheel. A negative value scrolls up. | | scroll_from_origin(self, scroll_origin: 'ScrollOrigin', delta_x: 'int', delta_y: 'int') -> 'ActionChains' | Scrolls by provided amount based on a provided origin. The scroll | origin is either the center of an element or the upper left of the | viewport plus any offsets. If the origin is an element, and the element | is not in the viewport, the bottom of the element will first be | scrolled to the bottom of the viewport. | | :Args: | - origin: Where scroll originates (viewport or element center) plus provided offsets. | - delta_x: Distance along X axis to scroll using the wheel. A negative value scrolls left. | - delta_y: Distance along Y axis to scroll using the wheel. A negative value scrolls up. | | :Raises: If the origin with offset is outside the viewport. | - MoveTargetOutOfBoundsException - If the origin with offset is outside the viewport. | | scroll_to_element(self, element: 'WebElement') -> 'ActionChains' | If the element is outside the viewport, scrolls the bottom of the | element to the bottom of the viewport. | | :Args: | - element: Which element to scroll into the viewport. | | send_keys(self, *keys_to_send: 'str') -> 'ActionChains' | Sends keys to current focused element. | | :Args: | - keys_to_send: The keys to send. Modifier keys constants can be found in the | 'Keys' class. | | send_keys_to_element(self, element: 'WebElement', *keys_to_send: 'str') -> 'ActionChains' | Sends keys to an element. | | :Args: | - element: The element to send keys. | - keys_to_send: The keys to send. Modifier keys constants can be found in the | 'Keys' class. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) Chrome = class WebDriver(selenium.webdriver.chromium.webdriver.ChromiumDriver) | Chrome(options: selenium.webdriver.chrome.options.Options = None, service: selenium.webdriver.chrome.service.Service = None, keep_alive: bool = True) -> None | | Controls the ChromeDriver and allows you to drive the browser. | | Method resolution order: | WebDriver | selenium.webdriver.chromium.webdriver.ChromiumDriver | selenium.webdriver.remote.webdriver.WebDriver | selenium.webdriver.remote.webdriver.BaseWebDriver | builtins.object | | Methods defined here: | | __init__(self, options: selenium.webdriver.chrome.options.Options = None, service: selenium.webdriver.chrome.service.Service = None, keep_alive: bool = True) -> None | Creates a new instance of the chrome driver. Starts the service and | then creates new instance of chrome driver. | | :Args: | - options - this takes an instance of ChromeOptions | - service - Service object for handling the browser driver if you need to pass extra details | - keep_alive - Whether to configure ChromeRemoteConnection to use HTTP keep-alive. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.chromium.webdriver.ChromiumDriver: | | delete_network_conditions(self) -> None | Resets Chromium network emulation settings. | | execute_cdp_cmd(self, cmd: str, cmd_args: dict) | Execute Chrome Devtools Protocol command and get returned result The | command and command args should follow chrome devtools protocol | domains/commands, refer to link | https://chromedevtools.github.io/devtools-protocol/ | | :Args: | - cmd: A str, command name | - cmd_args: A dict, command args. empty dict {} if there is no command args | :Usage: | :: | | driver.execute_cdp_cmd('Network.getResponseBody', {'requestId': requestId}) | :Returns: | A dict, empty dict {} if there is no result to return. | For example to getResponseBody: | {'base64Encoded': False, 'body': 'response body string'} | | get_issue_message(self) | :Returns: An error message when there is any issue in a Cast | session. | | get_network_conditions(self) | Gets Chromium network emulation settings. | | :Returns: A dict. For example: {'latency': 4, | 'download_throughput': 2, 'upload_throughput': 2, 'offline': | False} | | get_sinks(self) -> list | :Returns: A list of sinks available for Cast. | | launch_app(self, id) | Launches Chromium app specified by id. | | quit(self) -> None | Closes the browser and shuts down the ChromiumDriver executable that | is started when starting the ChromiumDriver. | | set_network_conditions(self, **network_conditions) -> None | Sets Chromium network emulation settings. | | :Args: | - network_conditions: A dict with conditions specification. | | :Usage: | :: | | driver.set_network_conditions( | offline=False, | latency=5, # additional latency (ms) | download_throughput=500 * 1024, # maximal throughput | upload_throughput=500 * 1024) # maximal throughput | | Note: 'throughput' can be used to set both (for download and upload). | | set_permissions(self, name: str, value: str) -> None | Sets Applicable Permission. | | :Args: | - name: The item to set the permission on. | - value: The value to set on the item | | :Usage: | :: | | driver.set_permissions('clipboard-read', 'denied') | | set_sink_to_use(self, sink_name: str) -> dict | Sets a specific sink, using its name, as a Cast session receiver | target. | | :Args: | - sink_name: Name of the sink to use as the target. | | start_desktop_mirroring(self, sink_name: str) -> dict | Starts a desktop mirroring session on a specific receiver target. | | :Args: | - sink_name: Name of the sink to use as the target. | | start_tab_mirroring(self, sink_name: str) -> dict | Starts a tab mirroring session on a specific receiver target. | | :Args: | - sink_name: Name of the sink to use as the target. | | stop_casting(self, sink_name: str) -> dict | Stops the existing Cast session on a specific receiver target. | | :Args: | - sink_name: Name of the sink to stop the Cast session. | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.remote.webdriver.WebDriver: | | __enter__(self) | | __exit__(self, exc_type: Optional[Type[BaseException]], exc: Optional[BaseException], traceback: Optional[traceback]) | | __repr__(self) | Return repr(self). | | add_cookie(self, cookie_dict) -> None | Adds a cookie to your current session. | | :Args: | - cookie_dict: A dictionary object, with required keys - "name" and "value"; | optional keys - "path", "domain", "secure", "httpOnly", "expiry", "sameSite" | | :Usage: | :: | | driver.add_cookie({'name' : 'foo', 'value' : 'bar'}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/'}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/', 'secure' : True}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'sameSite' : 'Strict'}) | | add_credential(self, credential: selenium.webdriver.common.virtual_authenticator.Credential) -> None | Injects a credential into the authenticator. | | add_virtual_authenticator(self, options: selenium.webdriver.common.virtual_authenticator.VirtualAuthenticatorOptions) -> None | Adds a virtual authenticator with the given options. | | back(self) -> None | Goes one step backward in the browser history. | | :Usage: | :: | | driver.back() | | bidi_connection(self) | | close(self) -> None | Closes the current window. | | :Usage: | :: | | driver.close() | | create_web_element(self, element_id: str) -> selenium.webdriver.remote.webelement.WebElement | Creates a web element with the specified `element_id`. | | delete_all_cookies(self) -> None | Delete all cookies in the scope of the session. | | :Usage: | :: | | driver.delete_all_cookies() | | delete_cookie(self, name) -> None | Deletes a single cookie with the given name. | | :Usage: | :: | | driver.delete_cookie('my_cookie') | | delete_downloadable_files(self) -> None | Deletes all downloadable files. | | download_file(self, file_name: str, target_directory: str) -> None | Downloads a file with the specified file name to the target | directory. | | file_name: The name of the file to download. | target_directory: The path to the directory to save the downloaded file. | | execute(self, driver_command: str, params: dict = None) -> dict | Sends a command to be executed by a command.CommandExecutor. | | :Args: | - driver_command: The name of the command to execute as a string. | - params: A dictionary of named parameters to send with the command. | | :Returns: | The command's JSON response loaded into a dictionary object. | | execute_async_script(self, script: str, *args) | Asynchronously Executes JavaScript in the current window/frame. | | :Args: | - script: The JavaScript to execute. | - \*args: Any applicable arguments for your JavaScript. | | :Usage: | :: | | script = "var callback = arguments[arguments.length - 1]; " \ | "window.setTimeout(function(){ callback('timeout') }, 3000);" | driver.execute_async_script(script) | | execute_script(self, script, *args) | Synchronously Executes JavaScript in the current window/frame. | | :Args: | - script: The JavaScript to execute. | - \*args: Any applicable arguments for your JavaScript. | | :Usage: | :: | | driver.execute_script('return document.title;') | | file_detector_context(self, file_detector_class, *args, **kwargs) | Overrides the current file detector (if necessary) in limited | context. Ensures the original file detector is set afterwards. | | Example:: | | with webdriver.file_detector_context(UselessFileDetector): | someinput.send_keys('/etc/hosts') | | :Args: | - file_detector_class - Class of the desired file detector. If the class is different | from the current file_detector, then the class is instantiated with args and kwargs | and used as a file detector during the duration of the context manager. | - args - Optional arguments that get passed to the file detector class during | instantiation. | - kwargs - Keyword arguments, passed the same way as args. | | find_element(self, by='id', value: Optional[str] = None) -> selenium.webdriver.remote.webelement.WebElement | Find an element given a By strategy and locator. | | :Usage: | :: | | element = driver.find_element(By.ID, 'foo') | | :rtype: WebElement | | find_elements(self, by='id', value: Optional[str] = None) -> List[selenium.webdriver.remote.webelement.WebElement] | Find elements given a By strategy and locator. | | :Usage: | :: | | elements = driver.find_elements(By.CLASS_NAME, 'foo') | | :rtype: list of WebElement | | forward(self) -> None | Goes one step forward in the browser history. | | :Usage: | :: | | driver.forward() | | fullscreen_window(self) -> None | Invokes the window manager-specific 'full screen' operation. | | get(self, url: str) -> None | Loads a web page in the current browser session. | | get_cookie(self, name) -> Optional[Dict] | Get a single cookie by name. Returns the cookie if found, None if | not. | | :Usage: | :: | | driver.get_cookie('my_cookie') | | get_cookies(self) -> List[dict] | Returns a set of dictionaries, corresponding to cookies visible in | the current session. | | :Usage: | :: | | driver.get_cookies() | | get_credentials(self) -> List[selenium.webdriver.common.virtual_authenticator.Credential] | Returns the list of credentials owned by the authenticator. | | get_downloadable_files(self) -> dict | Retrieves the downloadable files as a map of file names and their | corresponding URLs. | | get_log(self, log_type) | Gets the log for a given log type. | | :Args: | - log_type: type of log that which will be returned | | :Usage: | :: | | driver.get_log('browser') | driver.get_log('driver') | driver.get_log('client') | driver.get_log('server') | | get_pinned_scripts(self) -> List[str] | | get_screenshot_as_base64(self) -> str | Gets the screenshot of the current window as a base64 encoded string | which is useful in embedded images in HTML. | | :Usage: | :: | | driver.get_screenshot_as_base64() | | get_screenshot_as_file(self, filename) -> bool | Saves a screenshot of the current window to a PNG image file. | Returns False if there is any IOError, else returns True. Use full | paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.get_screenshot_as_file('/Screenshots/foo.png') | | get_screenshot_as_png(self) -> bytes | Gets the screenshot of the current window as a binary data. | | :Usage: | :: | | driver.get_screenshot_as_png() | | get_window_position(self, windowHandle='current') -> dict | Gets the x,y position of the current window. | | :Usage: | :: | | driver.get_window_position() | | get_window_rect(self) -> dict | Gets the x, y coordinates of the window as well as height and width | of the current window. | | :Usage: | :: | | driver.get_window_rect() | | get_window_size(self, windowHandle: str = 'current') -> dict | Gets the width and height of the current window. | | :Usage: | :: | | driver.get_window_size() | | implicitly_wait(self, time_to_wait: float) -> None | Sets a sticky timeout to implicitly wait for an element to be found, | or a command to complete. This method only needs to be called one time | per session. To set the timeout for calls to execute_async_script, see | set_script_timeout. | | :Args: | - time_to_wait: Amount of time to wait (in seconds) | | :Usage: | :: | | driver.implicitly_wait(30) | | maximize_window(self) -> None | Maximizes the current window that webdriver is using. | | minimize_window(self) -> None | Invokes the window manager-specific 'minimize' operation. | | pin_script(self, script: str, script_key=None) -> selenium.webdriver.remote.script_key.ScriptKey | Store common javascript scripts to be executed later by a unique | hashable ID. | | print_page(self, print_options: Optional[selenium.webdriver.common.print_page_options.PrintOptions] = None) -> str | Takes PDF of the current page. | | The driver makes a best effort to return a PDF based on the | provided parameters. | | refresh(self) -> None | Refreshes the current page. | | :Usage: | :: | | driver.refresh() | | remove_all_credentials(self) -> None | Removes all credentials from the authenticator. | | remove_credential(self, credential_id: Union[str, bytearray]) -> None | Removes a credential from the authenticator. | | remove_virtual_authenticator(self) -> None | Removes a previously added virtual authenticator. | | The authenticator is no longer valid after removal, so no | methods may be called. | | save_screenshot(self, filename) -> bool | Saves a screenshot of the current window to a PNG image file. | Returns False if there is any IOError, else returns True. Use full | paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.save_screenshot('/Screenshots/foo.png') | | set_page_load_timeout(self, time_to_wait: float) -> None | Set the amount of time to wait for a page load to complete before | throwing an error. | | :Args: | - time_to_wait: The amount of time to wait | | :Usage: | :: | | driver.set_page_load_timeout(30) | | set_script_timeout(self, time_to_wait: float) -> None | Set the amount of time that the script should wait during an | execute_async_script call before throwing an error. | | :Args: | - time_to_wait: The amount of time to wait (in seconds) | | :Usage: | :: | | driver.set_script_timeout(30) | | set_user_verified(self, verified: bool) -> None | Sets whether the authenticator will simulate success or fail on user | verification. | | verified: True if the authenticator will pass user verification, False otherwise. | | set_window_position(self, x, y, windowHandle: str = 'current') -> dict | Sets the x,y position of the current window. (window.moveTo) | | :Args: | - x: the x-coordinate in pixels to set the window position | - y: the y-coordinate in pixels to set the window position | | :Usage: | :: | | driver.set_window_position(0,0) | | set_window_rect(self, x=None, y=None, width=None, height=None) -> dict | Sets the x, y coordinates of the window as well as height and width | of the current window. This method is only supported for W3C compatible | browsers; other browsers should use `set_window_position` and | `set_window_size`. | | :Usage: | :: | | driver.set_window_rect(x=10, y=10) | driver.set_window_rect(width=100, height=200) | driver.set_window_rect(x=10, y=10, width=100, height=200) | | set_window_size(self, width, height, windowHandle: str = 'current') -> None | Sets the width and height of the current window. (window.resizeTo) | | :Args: | - width: the width in pixels to set the window to | - height: the height in pixels to set the window to | | :Usage: | :: | | driver.set_window_size(800,600) | | start_client(self) | Called before starting a new session. | | This method may be overridden to define custom startup behavior. | | start_session(self, capabilities: dict) -> None | Creates a new session with the desired capabilities. | | :Args: | - capabilities - a capabilities dict to start the session with. | | stop_client(self) | Called after executing a quit command. | | This method may be overridden to define custom shutdown | behavior. | | unpin(self, script_key: selenium.webdriver.remote.script_key.ScriptKey) -> None | Remove a pinned script from storage. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.remote.webdriver.WebDriver: | | application_cache | Returns a ApplicationCache Object to interact with the browser app | cache. | | capabilities | Returns the drivers current capabilities being used. | | current_url | Gets the URL of the current page. | | :Usage: | :: | | driver.current_url | | current_window_handle | Returns the handle of the current window. | | :Usage: | :: | | driver.current_window_handle | | desired_capabilities | Returns the drivers current desired capabilities being used. | | log_types | Gets a list of the available log types. This only works with w3c | compliant browsers. | | :Usage: | :: | | driver.log_types | | mobile | | name | Returns the name of the underlying browser for this instance. | | :Usage: | :: | | name = driver.name | | page_source | Gets the source of the current page. | | :Usage: | :: | | driver.page_source | | switch_to | :Returns: | - SwitchTo: an object containing all options to switch focus into | | :Usage: | :: | | element = driver.switch_to.active_element | alert = driver.switch_to.alert | driver.switch_to.default_content() | driver.switch_to.frame('frame_name') | driver.switch_to.frame(1) | driver.switch_to.frame(driver.find_elements(By.TAG_NAME, "iframe")[0]) | driver.switch_to.parent_frame() | driver.switch_to.window('main') | | title | Returns the title of the current page. | | :Usage: | :: | | title = driver.title | | virtual_authenticator_id | Returns the id of the virtual authenticator. | | window_handles | Returns the handles of all windows within the current session. | | :Usage: | :: | | driver.window_handles | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.remote.webdriver.WebDriver: | | file_detector | | orientation | Gets the current orientation of the device. | | :Usage: | :: | | orientation = driver.orientation | | timeouts | Get all the timeouts that have been set on the current session. | | :Usage: | :: | | driver.timeouts | :rtype: Timeout | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.remote.webdriver.BaseWebDriver: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) ChromeOptions = class Options(selenium.webdriver.chromium.options.ChromiumOptions) | ChromeOptions() -> None | | Method resolution order: | Options | selenium.webdriver.chromium.options.ChromiumOptions | selenium.webdriver.common.options.ArgOptions | selenium.webdriver.common.options.BaseOptions | builtins.object | | Methods defined here: | | enable_mobile(self, android_package: str = 'com.android.chrome', android_activity: Optional[str] = None, device_serial: Optional[str] = None) -> None | Enables mobile browser use for browsers that support it. | | :Args: | android_activity: The name of the android package to start | | ---------------------------------------------------------------------- | Readonly properties defined here: | | default_capabilities | Return minimal capabilities necessary as a dictionary. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.chromium.options.ChromiumOptions: | | __init__(self) -> None | Initialize self. See help(type(self)) for accurate signature. | | add_encoded_extension(self, extension: str) -> None | Adds Base64 encoded string with extension data to a list that will | be used to extract it to the ChromeDriver. | | :Args: | - extension: Base64 encoded string with extension data | | add_experimental_option(self, name: str, value: Union[str, int, dict, List[str]]) -> None | Adds an experimental option which is passed to chromium. | | :Args: | name: The experimental option name. | value: The option value. | | add_extension(self, extension: str) -> None | Adds the path to the extension to a list that will be used to | extract it to the ChromeDriver. | | :Args: | - extension: path to the \*.crx file | | to_capabilities(self) -> dict | Creates a capabilities with all the options that have been set | :Returns: A dictionary with everything. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.chromium.options.ChromiumOptions: | | experimental_options | :Returns: A dictionary of experimental options for chromium. | | extensions | :Returns: A list of encoded extensions that will be loaded. | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.chromium.options.ChromiumOptions: | | binary_location | :Returns: The location of the binary, otherwise an empty string. | | debugger_address | :Returns: The address of the remote devtools instance. | | ---------------------------------------------------------------------- | Data and other attributes inherited from selenium.webdriver.chromium.options.ChromiumOptions: | | KEY = 'goog:chromeOptions' | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.options.ArgOptions: | | add_argument(self, argument) | Adds an argument to the list. | | :Args: | - Sets the arguments | | ignore_local_proxy_environment_variables(self) -> None | By calling this you will ignore HTTP_PROXY and HTTPS_PROXY from | being picked up and used. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.options.ArgOptions: | | arguments | :Returns: A list of arguments needed for the browser. | | ---------------------------------------------------------------------- | Data and other attributes inherited from selenium.webdriver.common.options.ArgOptions: | | BINARY_LOCATION_ERROR = 'Binary Location Must be a String' | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.options.BaseOptions: | | set_capability(self, name, value) -> None | Sets a capability. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.options.BaseOptions: | | capabilities | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.common.options.BaseOptions: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | accept_insecure_certs | | browser_version | | enable_downloads | | page_load_strategy | | platform_name | | proxy | | set_window_rect | | strict_file_interactability | | timeouts | | unhandled_prompt_behavior ChromeService = class Service(selenium.webdriver.chromium.service.ChromiumService) | ChromeService(executable_path=None, port: int = 0, service_args: Optional[List[str]] = None, log_output: Union[int, str, IO[Any]] = None, env: Optional[Mapping[str, str]] = None, **kwargs) -> None | | A Service class that is responsible for the starting and stopping of | `chromedriver`. | | :param executable_path: install path of the chromedriver executable, defaults to `chromedriver`. | :param port: Port for the service to run on, defaults to 0 where the operating system will decide. | :param service_args: (Optional) List of args to be passed to the subprocess when launching the executable. | :param log_output: (Optional) int representation of STDOUT/DEVNULL, any IO instance or String path to file. | :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. | | Method resolution order: | Service | selenium.webdriver.chromium.service.ChromiumService | selenium.webdriver.common.service.Service | abc.ABC | builtins.object | | Methods defined here: | | __init__(self, executable_path=None, port: int = 0, service_args: Optional[List[str]] = None, log_output: Union[int, str, IO[Any]] = None, env: Optional[Mapping[str, str]] = None, **kwargs) -> None | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.chromium.service.ChromiumService: | | command_line_args(self) -> List[str] | A List of program arguments (excluding the executable). | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.service.Service: | | __del__(self) -> None | | assert_process_still_running(self) -> None | Check if the underlying process is still running. | | is_connectable(self) -> bool | Establishes a socket connection to determine if the service running | on the port is accessible. | | send_remote_shutdown_command(self) -> None | Dispatch an HTTP request to the shutdown endpoint for the service in | an attempt to stop it. | | start(self) -> None | Starts the Service. | | :Exceptions: | - WebDriverException : Raised either when it can't start the service | or when it can't connect to the service | | stop(self) -> None | Stops the service. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.service.Service: | | service_url | Gets the url of the Service. | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.common.service.Service: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | path ChromiumEdge = class WebDriver(selenium.webdriver.chromium.webdriver.ChromiumDriver) | ChromiumEdge(options: selenium.webdriver.edge.options.Options = None, service: selenium.webdriver.edge.service.Service = None, keep_alive=True) -> None | | Controls the MSEdgeDriver and allows you to drive the browser. | | Method resolution order: | WebDriver | selenium.webdriver.chromium.webdriver.ChromiumDriver | selenium.webdriver.remote.webdriver.WebDriver | selenium.webdriver.remote.webdriver.BaseWebDriver | builtins.object | | Methods defined here: | | __init__(self, options: selenium.webdriver.edge.options.Options = None, service: selenium.webdriver.edge.service.Service = None, keep_alive=True) -> None | Creates a new instance of the edge driver. Starts the service and | then creates new instance of edge driver. | | :Args: | - options - this takes an instance of EdgeOptions | - service - Service object for handling the browser driver if you need to pass extra details | - keep_alive - Whether to configure EdgeRemoteConnection to use HTTP keep-alive. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.chromium.webdriver.ChromiumDriver: | | delete_network_conditions(self) -> None | Resets Chromium network emulation settings. | | execute_cdp_cmd(self, cmd: str, cmd_args: dict) | Execute Chrome Devtools Protocol command and get returned result The | command and command args should follow chrome devtools protocol | domains/commands, refer to link | https://chromedevtools.github.io/devtools-protocol/ | | :Args: | - cmd: A str, command name | - cmd_args: A dict, command args. empty dict {} if there is no command args | :Usage: | :: | | driver.execute_cdp_cmd('Network.getResponseBody', {'requestId': requestId}) | :Returns: | A dict, empty dict {} if there is no result to return. | For example to getResponseBody: | {'base64Encoded': False, 'body': 'response body string'} | | get_issue_message(self) | :Returns: An error message when there is any issue in a Cast | session. | | get_network_conditions(self) | Gets Chromium network emulation settings. | | :Returns: A dict. For example: {'latency': 4, | 'download_throughput': 2, 'upload_throughput': 2, 'offline': | False} | | get_sinks(self) -> list | :Returns: A list of sinks available for Cast. | | launch_app(self, id) | Launches Chromium app specified by id. | | quit(self) -> None | Closes the browser and shuts down the ChromiumDriver executable that | is started when starting the ChromiumDriver. | | set_network_conditions(self, **network_conditions) -> None | Sets Chromium network emulation settings. | | :Args: | - network_conditions: A dict with conditions specification. | | :Usage: | :: | | driver.set_network_conditions( | offline=False, | latency=5, # additional latency (ms) | download_throughput=500 * 1024, # maximal throughput | upload_throughput=500 * 1024) # maximal throughput | | Note: 'throughput' can be used to set both (for download and upload). | | set_permissions(self, name: str, value: str) -> None | Sets Applicable Permission. | | :Args: | - name: The item to set the permission on. | - value: The value to set on the item | | :Usage: | :: | | driver.set_permissions('clipboard-read', 'denied') | | set_sink_to_use(self, sink_name: str) -> dict | Sets a specific sink, using its name, as a Cast session receiver | target. | | :Args: | - sink_name: Name of the sink to use as the target. | | start_desktop_mirroring(self, sink_name: str) -> dict | Starts a desktop mirroring session on a specific receiver target. | | :Args: | - sink_name: Name of the sink to use as the target. | | start_tab_mirroring(self, sink_name: str) -> dict | Starts a tab mirroring session on a specific receiver target. | | :Args: | - sink_name: Name of the sink to use as the target. | | stop_casting(self, sink_name: str) -> dict | Stops the existing Cast session on a specific receiver target. | | :Args: | - sink_name: Name of the sink to stop the Cast session. | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.remote.webdriver.WebDriver: | | __enter__(self) | | __exit__(self, exc_type: Optional[Type[BaseException]], exc: Optional[BaseException], traceback: Optional[traceback]) | | __repr__(self) | Return repr(self). | | add_cookie(self, cookie_dict) -> None | Adds a cookie to your current session. | | :Args: | - cookie_dict: A dictionary object, with required keys - "name" and "value"; | optional keys - "path", "domain", "secure", "httpOnly", "expiry", "sameSite" | | :Usage: | :: | | driver.add_cookie({'name' : 'foo', 'value' : 'bar'}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/'}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/', 'secure' : True}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'sameSite' : 'Strict'}) | | add_credential(self, credential: selenium.webdriver.common.virtual_authenticator.Credential) -> None | Injects a credential into the authenticator. | | add_virtual_authenticator(self, options: selenium.webdriver.common.virtual_authenticator.VirtualAuthenticatorOptions) -> None | Adds a virtual authenticator with the given options. | | back(self) -> None | Goes one step backward in the browser history. | | :Usage: | :: | | driver.back() | | bidi_connection(self) | | close(self) -> None | Closes the current window. | | :Usage: | :: | | driver.close() | | create_web_element(self, element_id: str) -> selenium.webdriver.remote.webelement.WebElement | Creates a web element with the specified `element_id`. | | delete_all_cookies(self) -> None | Delete all cookies in the scope of the session. | | :Usage: | :: | | driver.delete_all_cookies() | | delete_cookie(self, name) -> None | Deletes a single cookie with the given name. | | :Usage: | :: | | driver.delete_cookie('my_cookie') | | delete_downloadable_files(self) -> None | Deletes all downloadable files. | | download_file(self, file_name: str, target_directory: str) -> None | Downloads a file with the specified file name to the target | directory. | | file_name: The name of the file to download. | target_directory: The path to the directory to save the downloaded file. | | execute(self, driver_command: str, params: dict = None) -> dict | Sends a command to be executed by a command.CommandExecutor. | | :Args: | - driver_command: The name of the command to execute as a string. | - params: A dictionary of named parameters to send with the command. | | :Returns: | The command's JSON response loaded into a dictionary object. | | execute_async_script(self, script: str, *args) | Asynchronously Executes JavaScript in the current window/frame. | | :Args: | - script: The JavaScript to execute. | - \*args: Any applicable arguments for your JavaScript. | | :Usage: | :: | | script = "var callback = arguments[arguments.length - 1]; " \ | "window.setTimeout(function(){ callback('timeout') }, 3000);" | driver.execute_async_script(script) | | execute_script(self, script, *args) | Synchronously Executes JavaScript in the current window/frame. | | :Args: | - script: The JavaScript to execute. | - \*args: Any applicable arguments for your JavaScript. | | :Usage: | :: | | driver.execute_script('return document.title;') | | file_detector_context(self, file_detector_class, *args, **kwargs) | Overrides the current file detector (if necessary) in limited | context. Ensures the original file detector is set afterwards. | | Example:: | | with webdriver.file_detector_context(UselessFileDetector): | someinput.send_keys('/etc/hosts') | | :Args: | - file_detector_class - Class of the desired file detector. If the class is different | from the current file_detector, then the class is instantiated with args and kwargs | and used as a file detector during the duration of the context manager. | - args - Optional arguments that get passed to the file detector class during | instantiation. | - kwargs - Keyword arguments, passed the same way as args. | | find_element(self, by='id', value: Optional[str] = None) -> selenium.webdriver.remote.webelement.WebElement | Find an element given a By strategy and locator. | | :Usage: | :: | | element = driver.find_element(By.ID, 'foo') | | :rtype: WebElement | | find_elements(self, by='id', value: Optional[str] = None) -> List[selenium.webdriver.remote.webelement.WebElement] | Find elements given a By strategy and locator. | | :Usage: | :: | | elements = driver.find_elements(By.CLASS_NAME, 'foo') | | :rtype: list of WebElement | | forward(self) -> None | Goes one step forward in the browser history. | | :Usage: | :: | | driver.forward() | | fullscreen_window(self) -> None | Invokes the window manager-specific 'full screen' operation. | | get(self, url: str) -> None | Loads a web page in the current browser session. | | get_cookie(self, name) -> Optional[Dict] | Get a single cookie by name. Returns the cookie if found, None if | not. | | :Usage: | :: | | driver.get_cookie('my_cookie') | | get_cookies(self) -> List[dict] | Returns a set of dictionaries, corresponding to cookies visible in | the current session. | | :Usage: | :: | | driver.get_cookies() | | get_credentials(self) -> List[selenium.webdriver.common.virtual_authenticator.Credential] | Returns the list of credentials owned by the authenticator. | | get_downloadable_files(self) -> dict | Retrieves the downloadable files as a map of file names and their | corresponding URLs. | | get_log(self, log_type) | Gets the log for a given log type. | | :Args: | - log_type: type of log that which will be returned | | :Usage: | :: | | driver.get_log('browser') | driver.get_log('driver') | driver.get_log('client') | driver.get_log('server') | | get_pinned_scripts(self) -> List[str] | | get_screenshot_as_base64(self) -> str | Gets the screenshot of the current window as a base64 encoded string | which is useful in embedded images in HTML. | | :Usage: | :: | | driver.get_screenshot_as_base64() | | get_screenshot_as_file(self, filename) -> bool | Saves a screenshot of the current window to a PNG image file. | Returns False if there is any IOError, else returns True. Use full | paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.get_screenshot_as_file('/Screenshots/foo.png') | | get_screenshot_as_png(self) -> bytes | Gets the screenshot of the current window as a binary data. | | :Usage: | :: | | driver.get_screenshot_as_png() | | get_window_position(self, windowHandle='current') -> dict | Gets the x,y position of the current window. | | :Usage: | :: | | driver.get_window_position() | | get_window_rect(self) -> dict | Gets the x, y coordinates of the window as well as height and width | of the current window. | | :Usage: | :: | | driver.get_window_rect() | | get_window_size(self, windowHandle: str = 'current') -> dict | Gets the width and height of the current window. | | :Usage: | :: | | driver.get_window_size() | | implicitly_wait(self, time_to_wait: float) -> None | Sets a sticky timeout to implicitly wait for an element to be found, | or a command to complete. This method only needs to be called one time | per session. To set the timeout for calls to execute_async_script, see | set_script_timeout. | | :Args: | - time_to_wait: Amount of time to wait (in seconds) | | :Usage: | :: | | driver.implicitly_wait(30) | | maximize_window(self) -> None | Maximizes the current window that webdriver is using. | | minimize_window(self) -> None | Invokes the window manager-specific 'minimize' operation. | | pin_script(self, script: str, script_key=None) -> selenium.webdriver.remote.script_key.ScriptKey | Store common javascript scripts to be executed later by a unique | hashable ID. | | print_page(self, print_options: Optional[selenium.webdriver.common.print_page_options.PrintOptions] = None) -> str | Takes PDF of the current page. | | The driver makes a best effort to return a PDF based on the | provided parameters. | | refresh(self) -> None | Refreshes the current page. | | :Usage: | :: | | driver.refresh() | | remove_all_credentials(self) -> None | Removes all credentials from the authenticator. | | remove_credential(self, credential_id: Union[str, bytearray]) -> None | Removes a credential from the authenticator. | | remove_virtual_authenticator(self) -> None | Removes a previously added virtual authenticator. | | The authenticator is no longer valid after removal, so no | methods may be called. | | save_screenshot(self, filename) -> bool | Saves a screenshot of the current window to a PNG image file. | Returns False if there is any IOError, else returns True. Use full | paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.save_screenshot('/Screenshots/foo.png') | | set_page_load_timeout(self, time_to_wait: float) -> None | Set the amount of time to wait for a page load to complete before | throwing an error. | | :Args: | - time_to_wait: The amount of time to wait | | :Usage: | :: | | driver.set_page_load_timeout(30) | | set_script_timeout(self, time_to_wait: float) -> None | Set the amount of time that the script should wait during an | execute_async_script call before throwing an error. | | :Args: | - time_to_wait: The amount of time to wait (in seconds) | | :Usage: | :: | | driver.set_script_timeout(30) | | set_user_verified(self, verified: bool) -> None | Sets whether the authenticator will simulate success or fail on user | verification. | | verified: True if the authenticator will pass user verification, False otherwise. | | set_window_position(self, x, y, windowHandle: str = 'current') -> dict | Sets the x,y position of the current window. (window.moveTo) | | :Args: | - x: the x-coordinate in pixels to set the window position | - y: the y-coordinate in pixels to set the window position | | :Usage: | :: | | driver.set_window_position(0,0) | | set_window_rect(self, x=None, y=None, width=None, height=None) -> dict | Sets the x, y coordinates of the window as well as height and width | of the current window. This method is only supported for W3C compatible | browsers; other browsers should use `set_window_position` and | `set_window_size`. | | :Usage: | :: | | driver.set_window_rect(x=10, y=10) | driver.set_window_rect(width=100, height=200) | driver.set_window_rect(x=10, y=10, width=100, height=200) | | set_window_size(self, width, height, windowHandle: str = 'current') -> None | Sets the width and height of the current window. (window.resizeTo) | | :Args: | - width: the width in pixels to set the window to | - height: the height in pixels to set the window to | | :Usage: | :: | | driver.set_window_size(800,600) | | start_client(self) | Called before starting a new session. | | This method may be overridden to define custom startup behavior. | | start_session(self, capabilities: dict) -> None | Creates a new session with the desired capabilities. | | :Args: | - capabilities - a capabilities dict to start the session with. | | stop_client(self) | Called after executing a quit command. | | This method may be overridden to define custom shutdown | behavior. | | unpin(self, script_key: selenium.webdriver.remote.script_key.ScriptKey) -> None | Remove a pinned script from storage. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.remote.webdriver.WebDriver: | | application_cache | Returns a ApplicationCache Object to interact with the browser app | cache. | | capabilities | Returns the drivers current capabilities being used. | | current_url | Gets the URL of the current page. | | :Usage: | :: | | driver.current_url | | current_window_handle | Returns the handle of the current window. | | :Usage: | :: | | driver.current_window_handle | | desired_capabilities | Returns the drivers current desired capabilities being used. | | log_types | Gets a list of the available log types. This only works with w3c | compliant browsers. | | :Usage: | :: | | driver.log_types | | mobile | | name | Returns the name of the underlying browser for this instance. | | :Usage: | :: | | name = driver.name | | page_source | Gets the source of the current page. | | :Usage: | :: | | driver.page_source | | switch_to | :Returns: | - SwitchTo: an object containing all options to switch focus into | | :Usage: | :: | | element = driver.switch_to.active_element | alert = driver.switch_to.alert | driver.switch_to.default_content() | driver.switch_to.frame('frame_name') | driver.switch_to.frame(1) | driver.switch_to.frame(driver.find_elements(By.TAG_NAME, "iframe")[0]) | driver.switch_to.parent_frame() | driver.switch_to.window('main') | | title | Returns the title of the current page. | | :Usage: | :: | | title = driver.title | | virtual_authenticator_id | Returns the id of the virtual authenticator. | | window_handles | Returns the handles of all windows within the current session. | | :Usage: | :: | | driver.window_handles | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.remote.webdriver.WebDriver: | | file_detector | | orientation | Gets the current orientation of the device. | | :Usage: | :: | | orientation = driver.orientation | | timeouts | Get all the timeouts that have been set on the current session. | | :Usage: | :: | | driver.timeouts | :rtype: Timeout | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.remote.webdriver.BaseWebDriver: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) class DesiredCapabilities(builtins.object) | Set of default supported desired capabilities. | | Use this as a starting point for creating a desired capabilities object for | requesting remote webdrivers for connecting to selenium server or selenium grid. | | Usage Example:: | | from selenium import webdriver | | selenium_grid_url = "http://198.0.0.1:4444/wd/hub" | | # Create a desired capabilities object as a starting point. | capabilities = DesiredCapabilities.FIREFOX.copy() | capabilities['platform'] = "WINDOWS" | capabilities['version'] = "10" | | # Instantiate an instance of Remote WebDriver with the desired capabilities. | driver = webdriver.Remote(desired_capabilities=capabilities, | command_executor=selenium_grid_url) | | Note: Always use '.copy()' on the DesiredCapabilities object to avoid the side | effects of altering the Global class instance. | | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | CHROME = {'browserName': 'chrome'} | | EDGE = {'browserName': 'MicrosoftEdge'} | | FIREFOX = {'acceptInsecureCerts': True, 'browserName': 'firefox', 'moz... | | HTMLUNIT = {'browserName': 'htmlunit', 'platform': 'ANY', 'version': '... | | HTMLUNITWITHJS = {'browserName': 'htmlunit', 'javascriptEnabled': True... | | INTERNETEXPLORER = {'browserName': 'internet explorer', 'platformName'... | | IPAD = {'browserName': 'iPad', 'platform': 'mac', 'version': ''} | | IPHONE = {'browserName': 'iPhone', 'platform': 'mac', 'version': ''} | | SAFARI = {'browserName': 'safari', 'platformName': 'mac'} | | WEBKITGTK = {'browserName': 'MiniBrowser', 'platform': 'ANY', 'version... | | WPEWEBKIT = {'browserName': 'MiniBrowser', 'platform': 'ANY', 'version... Edge = class WebDriver(selenium.webdriver.chromium.webdriver.ChromiumDriver) | Edge(options: selenium.webdriver.edge.options.Options = None, service: selenium.webdriver.edge.service.Service = None, keep_alive=True) -> None | | Controls the MSEdgeDriver and allows you to drive the browser. | | Method resolution order: | WebDriver | selenium.webdriver.chromium.webdriver.ChromiumDriver | selenium.webdriver.remote.webdriver.WebDriver | selenium.webdriver.remote.webdriver.BaseWebDriver | builtins.object | | Methods defined here: | | __init__(self, options: selenium.webdriver.edge.options.Options = None, service: selenium.webdriver.edge.service.Service = None, keep_alive=True) -> None | Creates a new instance of the edge driver. Starts the service and | then creates new instance of edge driver. | | :Args: | - options - this takes an instance of EdgeOptions | - service - Service object for handling the browser driver if you need to pass extra details | - keep_alive - Whether to configure EdgeRemoteConnection to use HTTP keep-alive. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.chromium.webdriver.ChromiumDriver: | | delete_network_conditions(self) -> None | Resets Chromium network emulation settings. | | execute_cdp_cmd(self, cmd: str, cmd_args: dict) | Execute Chrome Devtools Protocol command and get returned result The | command and command args should follow chrome devtools protocol | domains/commands, refer to link | https://chromedevtools.github.io/devtools-protocol/ | | :Args: | - cmd: A str, command name | - cmd_args: A dict, command args. empty dict {} if there is no command args | :Usage: | :: | | driver.execute_cdp_cmd('Network.getResponseBody', {'requestId': requestId}) | :Returns: | A dict, empty dict {} if there is no result to return. | For example to getResponseBody: | {'base64Encoded': False, 'body': 'response body string'} | | get_issue_message(self) | :Returns: An error message when there is any issue in a Cast | session. | | get_network_conditions(self) | Gets Chromium network emulation settings. | | :Returns: A dict. For example: {'latency': 4, | 'download_throughput': 2, 'upload_throughput': 2, 'offline': | False} | | get_sinks(self) -> list | :Returns: A list of sinks available for Cast. | | launch_app(self, id) | Launches Chromium app specified by id. | | quit(self) -> None | Closes the browser and shuts down the ChromiumDriver executable that | is started when starting the ChromiumDriver. | | set_network_conditions(self, **network_conditions) -> None | Sets Chromium network emulation settings. | | :Args: | - network_conditions: A dict with conditions specification. | | :Usage: | :: | | driver.set_network_conditions( | offline=False, | latency=5, # additional latency (ms) | download_throughput=500 * 1024, # maximal throughput | upload_throughput=500 * 1024) # maximal throughput | | Note: 'throughput' can be used to set both (for download and upload). | | set_permissions(self, name: str, value: str) -> None | Sets Applicable Permission. | | :Args: | - name: The item to set the permission on. | - value: The value to set on the item | | :Usage: | :: | | driver.set_permissions('clipboard-read', 'denied') | | set_sink_to_use(self, sink_name: str) -> dict | Sets a specific sink, using its name, as a Cast session receiver | target. | | :Args: | - sink_name: Name of the sink to use as the target. | | start_desktop_mirroring(self, sink_name: str) -> dict | Starts a desktop mirroring session on a specific receiver target. | | :Args: | - sink_name: Name of the sink to use as the target. | | start_tab_mirroring(self, sink_name: str) -> dict | Starts a tab mirroring session on a specific receiver target. | | :Args: | - sink_name: Name of the sink to use as the target. | | stop_casting(self, sink_name: str) -> dict | Stops the existing Cast session on a specific receiver target. | | :Args: | - sink_name: Name of the sink to stop the Cast session. | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.remote.webdriver.WebDriver: | | __enter__(self) | | __exit__(self, exc_type: Optional[Type[BaseException]], exc: Optional[BaseException], traceback: Optional[traceback]) | | __repr__(self) | Return repr(self). | | add_cookie(self, cookie_dict) -> None | Adds a cookie to your current session. | | :Args: | - cookie_dict: A dictionary object, with required keys - "name" and "value"; | optional keys - "path", "domain", "secure", "httpOnly", "expiry", "sameSite" | | :Usage: | :: | | driver.add_cookie({'name' : 'foo', 'value' : 'bar'}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/'}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/', 'secure' : True}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'sameSite' : 'Strict'}) | | add_credential(self, credential: selenium.webdriver.common.virtual_authenticator.Credential) -> None | Injects a credential into the authenticator. | | add_virtual_authenticator(self, options: selenium.webdriver.common.virtual_authenticator.VirtualAuthenticatorOptions) -> None | Adds a virtual authenticator with the given options. | | back(self) -> None | Goes one step backward in the browser history. | | :Usage: | :: | | driver.back() | | bidi_connection(self) | | close(self) -> None | Closes the current window. | | :Usage: | :: | | driver.close() | | create_web_element(self, element_id: str) -> selenium.webdriver.remote.webelement.WebElement | Creates a web element with the specified `element_id`. | | delete_all_cookies(self) -> None | Delete all cookies in the scope of the session. | | :Usage: | :: | | driver.delete_all_cookies() | | delete_cookie(self, name) -> None | Deletes a single cookie with the given name. | | :Usage: | :: | | driver.delete_cookie('my_cookie') | | delete_downloadable_files(self) -> None | Deletes all downloadable files. | | download_file(self, file_name: str, target_directory: str) -> None | Downloads a file with the specified file name to the target | directory. | | file_name: The name of the file to download. | target_directory: The path to the directory to save the downloaded file. | | execute(self, driver_command: str, params: dict = None) -> dict | Sends a command to be executed by a command.CommandExecutor. | | :Args: | - driver_command: The name of the command to execute as a string. | - params: A dictionary of named parameters to send with the command. | | :Returns: | The command's JSON response loaded into a dictionary object. | | execute_async_script(self, script: str, *args) | Asynchronously Executes JavaScript in the current window/frame. | | :Args: | - script: The JavaScript to execute. | - \*args: Any applicable arguments for your JavaScript. | | :Usage: | :: | | script = "var callback = arguments[arguments.length - 1]; " \ | "window.setTimeout(function(){ callback('timeout') }, 3000);" | driver.execute_async_script(script) | | execute_script(self, script, *args) | Synchronously Executes JavaScript in the current window/frame. | | :Args: | - script: The JavaScript to execute. | - \*args: Any applicable arguments for your JavaScript. | | :Usage: | :: | | driver.execute_script('return document.title;') | | file_detector_context(self, file_detector_class, *args, **kwargs) | Overrides the current file detector (if necessary) in limited | context. Ensures the original file detector is set afterwards. | | Example:: | | with webdriver.file_detector_context(UselessFileDetector): | someinput.send_keys('/etc/hosts') | | :Args: | - file_detector_class - Class of the desired file detector. If the class is different | from the current file_detector, then the class is instantiated with args and kwargs | and used as a file detector during the duration of the context manager. | - args - Optional arguments that get passed to the file detector class during | instantiation. | - kwargs - Keyword arguments, passed the same way as args. | | find_element(self, by='id', value: Optional[str] = None) -> selenium.webdriver.remote.webelement.WebElement | Find an element given a By strategy and locator. | | :Usage: | :: | | element = driver.find_element(By.ID, 'foo') | | :rtype: WebElement | | find_elements(self, by='id', value: Optional[str] = None) -> List[selenium.webdriver.remote.webelement.WebElement] | Find elements given a By strategy and locator. | | :Usage: | :: | | elements = driver.find_elements(By.CLASS_NAME, 'foo') | | :rtype: list of WebElement | | forward(self) -> None | Goes one step forward in the browser history. | | :Usage: | :: | | driver.forward() | | fullscreen_window(self) -> None | Invokes the window manager-specific 'full screen' operation. | | get(self, url: str) -> None | Loads a web page in the current browser session. | | get_cookie(self, name) -> Optional[Dict] | Get a single cookie by name. Returns the cookie if found, None if | not. | | :Usage: | :: | | driver.get_cookie('my_cookie') | | get_cookies(self) -> List[dict] | Returns a set of dictionaries, corresponding to cookies visible in | the current session. | | :Usage: | :: | | driver.get_cookies() | | get_credentials(self) -> List[selenium.webdriver.common.virtual_authenticator.Credential] | Returns the list of credentials owned by the authenticator. | | get_downloadable_files(self) -> dict | Retrieves the downloadable files as a map of file names and their | corresponding URLs. | | get_log(self, log_type) | Gets the log for a given log type. | | :Args: | - log_type: type of log that which will be returned | | :Usage: | :: | | driver.get_log('browser') | driver.get_log('driver') | driver.get_log('client') | driver.get_log('server') | | get_pinned_scripts(self) -> List[str] | | get_screenshot_as_base64(self) -> str | Gets the screenshot of the current window as a base64 encoded string | which is useful in embedded images in HTML. | | :Usage: | :: | | driver.get_screenshot_as_base64() | | get_screenshot_as_file(self, filename) -> bool | Saves a screenshot of the current window to a PNG image file. | Returns False if there is any IOError, else returns True. Use full | paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.get_screenshot_as_file('/Screenshots/foo.png') | | get_screenshot_as_png(self) -> bytes | Gets the screenshot of the current window as a binary data. | | :Usage: | :: | | driver.get_screenshot_as_png() | | get_window_position(self, windowHandle='current') -> dict | Gets the x,y position of the current window. | | :Usage: | :: | | driver.get_window_position() | | get_window_rect(self) -> dict | Gets the x, y coordinates of the window as well as height and width | of the current window. | | :Usage: | :: | | driver.get_window_rect() | | get_window_size(self, windowHandle: str = 'current') -> dict | Gets the width and height of the current window. | | :Usage: | :: | | driver.get_window_size() | | implicitly_wait(self, time_to_wait: float) -> None | Sets a sticky timeout to implicitly wait for an element to be found, | or a command to complete. This method only needs to be called one time | per session. To set the timeout for calls to execute_async_script, see | set_script_timeout. | | :Args: | - time_to_wait: Amount of time to wait (in seconds) | | :Usage: | :: | | driver.implicitly_wait(30) | | maximize_window(self) -> None | Maximizes the current window that webdriver is using. | | minimize_window(self) -> None | Invokes the window manager-specific 'minimize' operation. | | pin_script(self, script: str, script_key=None) -> selenium.webdriver.remote.script_key.ScriptKey | Store common javascript scripts to be executed later by a unique | hashable ID. | | print_page(self, print_options: Optional[selenium.webdriver.common.print_page_options.PrintOptions] = None) -> str | Takes PDF of the current page. | | The driver makes a best effort to return a PDF based on the | provided parameters. | | refresh(self) -> None | Refreshes the current page. | | :Usage: | :: | | driver.refresh() | | remove_all_credentials(self) -> None | Removes all credentials from the authenticator. | | remove_credential(self, credential_id: Union[str, bytearray]) -> None | Removes a credential from the authenticator. | | remove_virtual_authenticator(self) -> None | Removes a previously added virtual authenticator. | | The authenticator is no longer valid after removal, so no | methods may be called. | | save_screenshot(self, filename) -> bool | Saves a screenshot of the current window to a PNG image file. | Returns False if there is any IOError, else returns True. Use full | paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.save_screenshot('/Screenshots/foo.png') | | set_page_load_timeout(self, time_to_wait: float) -> None | Set the amount of time to wait for a page load to complete before | throwing an error. | | :Args: | - time_to_wait: The amount of time to wait | | :Usage: | :: | | driver.set_page_load_timeout(30) | | set_script_timeout(self, time_to_wait: float) -> None | Set the amount of time that the script should wait during an | execute_async_script call before throwing an error. | | :Args: | - time_to_wait: The amount of time to wait (in seconds) | | :Usage: | :: | | driver.set_script_timeout(30) | | set_user_verified(self, verified: bool) -> None | Sets whether the authenticator will simulate success or fail on user | verification. | | verified: True if the authenticator will pass user verification, False otherwise. | | set_window_position(self, x, y, windowHandle: str = 'current') -> dict | Sets the x,y position of the current window. (window.moveTo) | | :Args: | - x: the x-coordinate in pixels to set the window position | - y: the y-coordinate in pixels to set the window position | | :Usage: | :: | | driver.set_window_position(0,0) | | set_window_rect(self, x=None, y=None, width=None, height=None) -> dict | Sets the x, y coordinates of the window as well as height and width | of the current window. This method is only supported for W3C compatible | browsers; other browsers should use `set_window_position` and | `set_window_size`. | | :Usage: | :: | | driver.set_window_rect(x=10, y=10) | driver.set_window_rect(width=100, height=200) | driver.set_window_rect(x=10, y=10, width=100, height=200) | | set_window_size(self, width, height, windowHandle: str = 'current') -> None | Sets the width and height of the current window. (window.resizeTo) | | :Args: | - width: the width in pixels to set the window to | - height: the height in pixels to set the window to | | :Usage: | :: | | driver.set_window_size(800,600) | | start_client(self) | Called before starting a new session. | | This method may be overridden to define custom startup behavior. | | start_session(self, capabilities: dict) -> None | Creates a new session with the desired capabilities. | | :Args: | - capabilities - a capabilities dict to start the session with. | | stop_client(self) | Called after executing a quit command. | | This method may be overridden to define custom shutdown | behavior. | | unpin(self, script_key: selenium.webdriver.remote.script_key.ScriptKey) -> None | Remove a pinned script from storage. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.remote.webdriver.WebDriver: | | application_cache | Returns a ApplicationCache Object to interact with the browser app | cache. | | capabilities | Returns the drivers current capabilities being used. | | current_url | Gets the URL of the current page. | | :Usage: | :: | | driver.current_url | | current_window_handle | Returns the handle of the current window. | | :Usage: | :: | | driver.current_window_handle | | desired_capabilities | Returns the drivers current desired capabilities being used. | | log_types | Gets a list of the available log types. This only works with w3c | compliant browsers. | | :Usage: | :: | | driver.log_types | | mobile | | name | Returns the name of the underlying browser for this instance. | | :Usage: | :: | | name = driver.name | | page_source | Gets the source of the current page. | | :Usage: | :: | | driver.page_source | | switch_to | :Returns: | - SwitchTo: an object containing all options to switch focus into | | :Usage: | :: | | element = driver.switch_to.active_element | alert = driver.switch_to.alert | driver.switch_to.default_content() | driver.switch_to.frame('frame_name') | driver.switch_to.frame(1) | driver.switch_to.frame(driver.find_elements(By.TAG_NAME, "iframe")[0]) | driver.switch_to.parent_frame() | driver.switch_to.window('main') | | title | Returns the title of the current page. | | :Usage: | :: | | title = driver.title | | virtual_authenticator_id | Returns the id of the virtual authenticator. | | window_handles | Returns the handles of all windows within the current session. | | :Usage: | :: | | driver.window_handles | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.remote.webdriver.WebDriver: | | file_detector | | orientation | Gets the current orientation of the device. | | :Usage: | :: | | orientation = driver.orientation | | timeouts | Get all the timeouts that have been set on the current session. | | :Usage: | :: | | driver.timeouts | :rtype: Timeout | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.remote.webdriver.BaseWebDriver: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) EdgeOptions = class Options(selenium.webdriver.chromium.options.ChromiumOptions) | EdgeOptions() -> None | | Method resolution order: | Options | selenium.webdriver.chromium.options.ChromiumOptions | selenium.webdriver.common.options.ArgOptions | selenium.webdriver.common.options.BaseOptions | builtins.object | | Methods defined here: | | __init__(self) -> None | Initialize self. See help(type(self)) for accurate signature. | | to_capabilities(self) -> dict | Creates a capabilities with all the options that have been set and | :Returns: A dictionary with everything. | | ---------------------------------------------------------------------- | Readonly properties defined here: | | default_capabilities | Return minimal capabilities necessary as a dictionary. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | use_webview | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | KEY = 'ms:edgeOptions' | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.chromium.options.ChromiumOptions: | | add_encoded_extension(self, extension: str) -> None | Adds Base64 encoded string with extension data to a list that will | be used to extract it to the ChromeDriver. | | :Args: | - extension: Base64 encoded string with extension data | | add_experimental_option(self, name: str, value: Union[str, int, dict, List[str]]) -> None | Adds an experimental option which is passed to chromium. | | :Args: | name: The experimental option name. | value: The option value. | | add_extension(self, extension: str) -> None | Adds the path to the extension to a list that will be used to | extract it to the ChromeDriver. | | :Args: | - extension: path to the \*.crx file | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.chromium.options.ChromiumOptions: | | experimental_options | :Returns: A dictionary of experimental options for chromium. | | extensions | :Returns: A list of encoded extensions that will be loaded. | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.chromium.options.ChromiumOptions: | | binary_location | :Returns: The location of the binary, otherwise an empty string. | | debugger_address | :Returns: The address of the remote devtools instance. | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.options.ArgOptions: | | add_argument(self, argument) | Adds an argument to the list. | | :Args: | - Sets the arguments | | ignore_local_proxy_environment_variables(self) -> None | By calling this you will ignore HTTP_PROXY and HTTPS_PROXY from | being picked up and used. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.options.ArgOptions: | | arguments | :Returns: A list of arguments needed for the browser. | | ---------------------------------------------------------------------- | Data and other attributes inherited from selenium.webdriver.common.options.ArgOptions: | | BINARY_LOCATION_ERROR = 'Binary Location Must be a String' | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.options.BaseOptions: | | enable_mobile(self, android_package: Optional[str] = None, android_activity: Optional[str] = None, device_serial: Optional[str] = None) -> None | Enables mobile browser use for browsers that support it. | | :Args: | android_activity: The name of the android package to start | | set_capability(self, name, value) -> None | Sets a capability. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.options.BaseOptions: | | capabilities | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.common.options.BaseOptions: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | accept_insecure_certs | | browser_version | | enable_downloads | | page_load_strategy | | platform_name | | proxy | | set_window_rect | | strict_file_interactability | | timeouts | | unhandled_prompt_behavior EdgeService = class Service(selenium.webdriver.chromium.service.ChromiumService) | EdgeService(executable_path: str = None, port: int = 0, verbose: bool = False, log_output: Union[int, str, IO[Any]] = None, service_args: Optional[List[str]] = None, env: Optional[Mapping[str, str]] = None, **kwargs) -> None | | A Service class that is responsible for the starting and stopping of | `msedgedriver`. | | :param executable_path: install path of the msedgedriver executable, defaults to `msedgedriver`. | :param port: Port for the service to run on, defaults to 0 where the operating system will decide. | :param verbose: (Deprecated) Whether to make the webdriver more verbose (passes the --verbose option to the binary). | Defaults to False. | :param log_output: (Optional) int representation of STDOUT/DEVNULL, any IO instance or String path to file. | :param service_args: (Optional) List of args to be passed to the subprocess when launching the executable. | :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. | | Method resolution order: | Service | selenium.webdriver.chromium.service.ChromiumService | selenium.webdriver.common.service.Service | abc.ABC | builtins.object | | Methods defined here: | | __init__(self, executable_path: str = None, port: int = 0, verbose: bool = False, log_output: Union[int, str, IO[Any]] = None, service_args: Optional[List[str]] = None, env: Optional[Mapping[str, str]] = None, **kwargs) -> None | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.chromium.service.ChromiumService: | | command_line_args(self) -> List[str] | A List of program arguments (excluding the executable). | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.service.Service: | | __del__(self) -> None | | assert_process_still_running(self) -> None | Check if the underlying process is still running. | | is_connectable(self) -> bool | Establishes a socket connection to determine if the service running | on the port is accessible. | | send_remote_shutdown_command(self) -> None | Dispatch an HTTP request to the shutdown endpoint for the service in | an attempt to stop it. | | start(self) -> None | Starts the Service. | | :Exceptions: | - WebDriverException : Raised either when it can't start the service | or when it can't connect to the service | | stop(self) -> None | Stops the service. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.service.Service: | | service_url | Gets the url of the Service. | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.common.service.Service: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | path Firefox = class WebDriver(selenium.webdriver.remote.webdriver.WebDriver) | Firefox(options: selenium.webdriver.firefox.options.Options = None, service: selenium.webdriver.firefox.service.Service = None, keep_alive=True) -> None | | Controls the GeckoDriver and allows you to drive the browser. | | Method resolution order: | WebDriver | selenium.webdriver.remote.webdriver.WebDriver | selenium.webdriver.remote.webdriver.BaseWebDriver | builtins.object | | Methods defined here: | | __init__(self, options: selenium.webdriver.firefox.options.Options = None, service: selenium.webdriver.firefox.service.Service = None, keep_alive=True) -> None | Creates a new instance of the Firefox driver. Starts the service and | then creates new instance of Firefox driver. | | :Args: | - options - Instance of ``options.Options``. | - service - (Optional) service instance for managing the starting and stopping of the driver. | - keep_alive - Whether to configure remote_connection.RemoteConnection to use HTTP keep-alive. | | context(self, context) | Sets the context that Selenium commands are running in using a | `with` statement. The state of the context on the server is saved | before entering the block, and restored upon exiting it. | | :param context: Context, may be one of the class properties | `CONTEXT_CHROME` or `CONTEXT_CONTENT`. | | Usage example:: | | with selenium.context(selenium.CONTEXT_CHROME): | # chrome scope | ... do stuff ... | | get_full_page_screenshot_as_base64(self) -> str | Gets the full document screenshot of the current window as a base64 | encoded string which is useful in embedded images in HTML. | | :Usage: | :: | | driver.get_full_page_screenshot_as_base64() | | get_full_page_screenshot_as_file(self, filename) -> bool | Saves a full document screenshot of the current window to a PNG | image file. Returns False if there is any IOError, else returns True. | Use full paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.get_full_page_screenshot_as_file('/Screenshots/foo.png') | | get_full_page_screenshot_as_png(self) -> bytes | Gets the full document screenshot of the current window as a binary | data. | | :Usage: | :: | | driver.get_full_page_screenshot_as_png() | | install_addon(self, path, temporary=False) -> str | Installs Firefox addon. | | Returns identifier of installed addon. This identifier can later | be used to uninstall addon. | | :param temporary: allows you to load browser extensions temporarily during a session | :param path: Absolute path to the addon that will be installed. | | :Usage: | :: | | driver.install_addon('/path/to/firebug.xpi') | | quit(self) -> None | Quits the driver and close every associated window. | | save_full_page_screenshot(self, filename) -> bool | Saves a full document screenshot of the current window to a PNG | image file. Returns False if there is any IOError, else returns True. | Use full paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.save_full_page_screenshot('/Screenshots/foo.png') | | set_context(self, context) -> None | | uninstall_addon(self, identifier) -> None | Uninstalls Firefox addon using its identifier. | | :Usage: | :: | | driver.uninstall_addon('addon@foo.com') | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | CONTEXT_CHROME = 'chrome' | | CONTEXT_CONTENT = 'content' | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.remote.webdriver.WebDriver: | | __enter__(self) | | __exit__(self, exc_type: Optional[Type[BaseException]], exc: Optional[BaseException], traceback: Optional[traceback]) | | __repr__(self) | Return repr(self). | | add_cookie(self, cookie_dict) -> None | Adds a cookie to your current session. | | :Args: | - cookie_dict: A dictionary object, with required keys - "name" and "value"; | optional keys - "path", "domain", "secure", "httpOnly", "expiry", "sameSite" | | :Usage: | :: | | driver.add_cookie({'name' : 'foo', 'value' : 'bar'}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/'}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/', 'secure' : True}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'sameSite' : 'Strict'}) | | add_credential(self, credential: selenium.webdriver.common.virtual_authenticator.Credential) -> None | Injects a credential into the authenticator. | | add_virtual_authenticator(self, options: selenium.webdriver.common.virtual_authenticator.VirtualAuthenticatorOptions) -> None | Adds a virtual authenticator with the given options. | | back(self) -> None | Goes one step backward in the browser history. | | :Usage: | :: | | driver.back() | | bidi_connection(self) | | close(self) -> None | Closes the current window. | | :Usage: | :: | | driver.close() | | create_web_element(self, element_id: str) -> selenium.webdriver.remote.webelement.WebElement | Creates a web element with the specified `element_id`. | | delete_all_cookies(self) -> None | Delete all cookies in the scope of the session. | | :Usage: | :: | | driver.delete_all_cookies() | | delete_cookie(self, name) -> None | Deletes a single cookie with the given name. | | :Usage: | :: | | driver.delete_cookie('my_cookie') | | delete_downloadable_files(self) -> None | Deletes all downloadable files. | | download_file(self, file_name: str, target_directory: str) -> None | Downloads a file with the specified file name to the target | directory. | | file_name: The name of the file to download. | target_directory: The path to the directory to save the downloaded file. | | execute(self, driver_command: str, params: dict = None) -> dict | Sends a command to be executed by a command.CommandExecutor. | | :Args: | - driver_command: The name of the command to execute as a string. | - params: A dictionary of named parameters to send with the command. | | :Returns: | The command's JSON response loaded into a dictionary object. | | execute_async_script(self, script: str, *args) | Asynchronously Executes JavaScript in the current window/frame. | | :Args: | - script: The JavaScript to execute. | - \*args: Any applicable arguments for your JavaScript. | | :Usage: | :: | | script = "var callback = arguments[arguments.length - 1]; " \ | "window.setTimeout(function(){ callback('timeout') }, 3000);" | driver.execute_async_script(script) | | execute_script(self, script, *args) | Synchronously Executes JavaScript in the current window/frame. | | :Args: | - script: The JavaScript to execute. | - \*args: Any applicable arguments for your JavaScript. | | :Usage: | :: | | driver.execute_script('return document.title;') | | file_detector_context(self, file_detector_class, *args, **kwargs) | Overrides the current file detector (if necessary) in limited | context. Ensures the original file detector is set afterwards. | | Example:: | | with webdriver.file_detector_context(UselessFileDetector): | someinput.send_keys('/etc/hosts') | | :Args: | - file_detector_class - Class of the desired file detector. If the class is different | from the current file_detector, then the class is instantiated with args and kwargs | and used as a file detector during the duration of the context manager. | - args - Optional arguments that get passed to the file detector class during | instantiation. | - kwargs - Keyword arguments, passed the same way as args. | | find_element(self, by='id', value: Optional[str] = None) -> selenium.webdriver.remote.webelement.WebElement | Find an element given a By strategy and locator. | | :Usage: | :: | | element = driver.find_element(By.ID, 'foo') | | :rtype: WebElement | | find_elements(self, by='id', value: Optional[str] = None) -> List[selenium.webdriver.remote.webelement.WebElement] | Find elements given a By strategy and locator. | | :Usage: | :: | | elements = driver.find_elements(By.CLASS_NAME, 'foo') | | :rtype: list of WebElement | | forward(self) -> None | Goes one step forward in the browser history. | | :Usage: | :: | | driver.forward() | | fullscreen_window(self) -> None | Invokes the window manager-specific 'full screen' operation. | | get(self, url: str) -> None | Loads a web page in the current browser session. | | get_cookie(self, name) -> Optional[Dict] | Get a single cookie by name. Returns the cookie if found, None if | not. | | :Usage: | :: | | driver.get_cookie('my_cookie') | | get_cookies(self) -> List[dict] | Returns a set of dictionaries, corresponding to cookies visible in | the current session. | | :Usage: | :: | | driver.get_cookies() | | get_credentials(self) -> List[selenium.webdriver.common.virtual_authenticator.Credential] | Returns the list of credentials owned by the authenticator. | | get_downloadable_files(self) -> dict | Retrieves the downloadable files as a map of file names and their | corresponding URLs. | | get_log(self, log_type) | Gets the log for a given log type. | | :Args: | - log_type: type of log that which will be returned | | :Usage: | :: | | driver.get_log('browser') | driver.get_log('driver') | driver.get_log('client') | driver.get_log('server') | | get_pinned_scripts(self) -> List[str] | | get_screenshot_as_base64(self) -> str | Gets the screenshot of the current window as a base64 encoded string | which is useful in embedded images in HTML. | | :Usage: | :: | | driver.get_screenshot_as_base64() | | get_screenshot_as_file(self, filename) -> bool | Saves a screenshot of the current window to a PNG image file. | Returns False if there is any IOError, else returns True. Use full | paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.get_screenshot_as_file('/Screenshots/foo.png') | | get_screenshot_as_png(self) -> bytes | Gets the screenshot of the current window as a binary data. | | :Usage: | :: | | driver.get_screenshot_as_png() | | get_window_position(self, windowHandle='current') -> dict | Gets the x,y position of the current window. | | :Usage: | :: | | driver.get_window_position() | | get_window_rect(self) -> dict | Gets the x, y coordinates of the window as well as height and width | of the current window. | | :Usage: | :: | | driver.get_window_rect() | | get_window_size(self, windowHandle: str = 'current') -> dict | Gets the width and height of the current window. | | :Usage: | :: | | driver.get_window_size() | | implicitly_wait(self, time_to_wait: float) -> None | Sets a sticky timeout to implicitly wait for an element to be found, | or a command to complete. This method only needs to be called one time | per session. To set the timeout for calls to execute_async_script, see | set_script_timeout. | | :Args: | - time_to_wait: Amount of time to wait (in seconds) | | :Usage: | :: | | driver.implicitly_wait(30) | | maximize_window(self) -> None | Maximizes the current window that webdriver is using. | | minimize_window(self) -> None | Invokes the window manager-specific 'minimize' operation. | | pin_script(self, script: str, script_key=None) -> selenium.webdriver.remote.script_key.ScriptKey | Store common javascript scripts to be executed later by a unique | hashable ID. | | print_page(self, print_options: Optional[selenium.webdriver.common.print_page_options.PrintOptions] = None) -> str | Takes PDF of the current page. | | The driver makes a best effort to return a PDF based on the | provided parameters. | | refresh(self) -> None | Refreshes the current page. | | :Usage: | :: | | driver.refresh() | | remove_all_credentials(self) -> None | Removes all credentials from the authenticator. | | remove_credential(self, credential_id: Union[str, bytearray]) -> None | Removes a credential from the authenticator. | | remove_virtual_authenticator(self) -> None | Removes a previously added virtual authenticator. | | The authenticator is no longer valid after removal, so no | methods may be called. | | save_screenshot(self, filename) -> bool | Saves a screenshot of the current window to a PNG image file. | Returns False if there is any IOError, else returns True. Use full | paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.save_screenshot('/Screenshots/foo.png') | | set_page_load_timeout(self, time_to_wait: float) -> None | Set the amount of time to wait for a page load to complete before | throwing an error. | | :Args: | - time_to_wait: The amount of time to wait | | :Usage: | :: | | driver.set_page_load_timeout(30) | | set_script_timeout(self, time_to_wait: float) -> None | Set the amount of time that the script should wait during an | execute_async_script call before throwing an error. | | :Args: | - time_to_wait: The amount of time to wait (in seconds) | | :Usage: | :: | | driver.set_script_timeout(30) | | set_user_verified(self, verified: bool) -> None | Sets whether the authenticator will simulate success or fail on user | verification. | | verified: True if the authenticator will pass user verification, False otherwise. | | set_window_position(self, x, y, windowHandle: str = 'current') -> dict | Sets the x,y position of the current window. (window.moveTo) | | :Args: | - x: the x-coordinate in pixels to set the window position | - y: the y-coordinate in pixels to set the window position | | :Usage: | :: | | driver.set_window_position(0,0) | | set_window_rect(self, x=None, y=None, width=None, height=None) -> dict | Sets the x, y coordinates of the window as well as height and width | of the current window. This method is only supported for W3C compatible | browsers; other browsers should use `set_window_position` and | `set_window_size`. | | :Usage: | :: | | driver.set_window_rect(x=10, y=10) | driver.set_window_rect(width=100, height=200) | driver.set_window_rect(x=10, y=10, width=100, height=200) | | set_window_size(self, width, height, windowHandle: str = 'current') -> None | Sets the width and height of the current window. (window.resizeTo) | | :Args: | - width: the width in pixels to set the window to | - height: the height in pixels to set the window to | | :Usage: | :: | | driver.set_window_size(800,600) | | start_client(self) | Called before starting a new session. | | This method may be overridden to define custom startup behavior. | | start_session(self, capabilities: dict) -> None | Creates a new session with the desired capabilities. | | :Args: | - capabilities - a capabilities dict to start the session with. | | stop_client(self) | Called after executing a quit command. | | This method may be overridden to define custom shutdown | behavior. | | unpin(self, script_key: selenium.webdriver.remote.script_key.ScriptKey) -> None | Remove a pinned script from storage. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.remote.webdriver.WebDriver: | | application_cache | Returns a ApplicationCache Object to interact with the browser app | cache. | | capabilities | Returns the drivers current capabilities being used. | | current_url | Gets the URL of the current page. | | :Usage: | :: | | driver.current_url | | current_window_handle | Returns the handle of the current window. | | :Usage: | :: | | driver.current_window_handle | | desired_capabilities | Returns the drivers current desired capabilities being used. | | log_types | Gets a list of the available log types. This only works with w3c | compliant browsers. | | :Usage: | :: | | driver.log_types | | mobile | | name | Returns the name of the underlying browser for this instance. | | :Usage: | :: | | name = driver.name | | page_source | Gets the source of the current page. | | :Usage: | :: | | driver.page_source | | switch_to | :Returns: | - SwitchTo: an object containing all options to switch focus into | | :Usage: | :: | | element = driver.switch_to.active_element | alert = driver.switch_to.alert | driver.switch_to.default_content() | driver.switch_to.frame('frame_name') | driver.switch_to.frame(1) | driver.switch_to.frame(driver.find_elements(By.TAG_NAME, "iframe")[0]) | driver.switch_to.parent_frame() | driver.switch_to.window('main') | | title | Returns the title of the current page. | | :Usage: | :: | | title = driver.title | | virtual_authenticator_id | Returns the id of the virtual authenticator. | | window_handles | Returns the handles of all windows within the current session. | | :Usage: | :: | | driver.window_handles | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.remote.webdriver.WebDriver: | | file_detector | | orientation | Gets the current orientation of the device. | | :Usage: | :: | | orientation = driver.orientation | | timeouts | Get all the timeouts that have been set on the current session. | | :Usage: | :: | | driver.timeouts | :rtype: Timeout | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.remote.webdriver.BaseWebDriver: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) FirefoxOptions = class Options(selenium.webdriver.common.options.ArgOptions) | FirefoxOptions() -> None | | Method resolution order: | Options | selenium.webdriver.common.options.ArgOptions | selenium.webdriver.common.options.BaseOptions | builtins.object | | Methods defined here: | | __init__(self) -> None | Initialize self. See help(type(self)) for accurate signature. | | enable_mobile(self, android_package: str = 'org.mozilla.firefox', android_activity=None, device_serial=None) | Enables mobile browser use for browsers that support it. | | :Args: | android_activity: The name of the android package to start | | set_preference(self, name: str, value: Union[str, int, bool]) | Sets a preference. | | to_capabilities(self) -> dict | Marshals the Firefox options to a `moz:firefoxOptions` object. | | ---------------------------------------------------------------------- | Readonly properties defined here: | | default_capabilities | Return minimal capabilities necessary as a dictionary. | | preferences | :Returns: A dict of preferences. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | binary | Returns the FirefoxBinary instance. | | binary_location | :Returns: The location of the binary. | | profile | :Returns: The Firefox profile to use. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | KEY = 'moz:firefoxOptions' | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.options.ArgOptions: | | add_argument(self, argument) | Adds an argument to the list. | | :Args: | - Sets the arguments | | ignore_local_proxy_environment_variables(self) -> None | By calling this you will ignore HTTP_PROXY and HTTPS_PROXY from | being picked up and used. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.options.ArgOptions: | | arguments | :Returns: A list of arguments needed for the browser. | | ---------------------------------------------------------------------- | Data and other attributes inherited from selenium.webdriver.common.options.ArgOptions: | | BINARY_LOCATION_ERROR = 'Binary Location Must be a String' | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.options.BaseOptions: | | set_capability(self, name, value) -> None | Sets a capability. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.options.BaseOptions: | | capabilities | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.common.options.BaseOptions: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | accept_insecure_certs | | browser_version | | enable_downloads | | page_load_strategy | | platform_name | | proxy | | set_window_rect | | strict_file_interactability | | timeouts | | unhandled_prompt_behavior class FirefoxProfile(builtins.object) | FirefoxProfile(profile_directory=None) | | Methods defined here: | | __init__(self, profile_directory=None) | Initialises a new instance of a Firefox Profile. | | :args: | - profile_directory: Directory of profile that you want to use. If a | directory is passed in it will be cloned and the cloned directory | will be used by the driver when instantiated. | This defaults to None and will create a new | directory when object is created. | | add_extension(self, extension='webdriver.xpi') | | set_preference(self, key, value) | Sets the preference that we want in the profile. | | update_preferences(self) | | ---------------------------------------------------------------------- | Readonly properties defined here: | | encoded | A zipped, base64 encoded string of profile directory for use with | remote WebDriver JSON wire protocol. | | path | Gets the profile directory that is currently being used. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | accept_untrusted_certs | | assume_untrusted_cert_issuer | | port | Gets the port that WebDriver is working on. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | ANONYMOUS_PROFILE_NAME = 'WEBDRIVER_ANONYMOUS_PROFILE' | | DEFAULT_PREFERENCES = None FirefoxService = class Service(selenium.webdriver.common.service.Service) | FirefoxService(executable_path: str = None, port: int = 0, service_args: Optional[List[str]] = None, log_output: Union[int, str, IO[Any]] = None, env: Optional[Mapping[str, str]] = None, **kwargs) -> None | | A Service class that is responsible for the starting and stopping of | `geckodriver`. | | :param executable_path: install path of the geckodriver executable, defaults to `geckodriver`. | :param port: Port for the service to run on, defaults to 0 where the operating system will decide. | :param service_args: (Optional) List of args to be passed to the subprocess when launching the executable. | :param log_output: (Optional) int representation of STDOUT/DEVNULL, any IO instance or String path to file. | :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. | | Method resolution order: | Service | selenium.webdriver.common.service.Service | abc.ABC | builtins.object | | Methods defined here: | | __init__(self, executable_path: str = None, port: int = 0, service_args: Optional[List[str]] = None, log_output: Union[int, str, IO[Any]] = None, env: Optional[Mapping[str, str]] = None, **kwargs) -> None | Initialize self. See help(type(self)) for accurate signature. | | command_line_args(self) -> List[str] | A List of program arguments (excluding the executable). | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.service.Service: | | __del__(self) -> None | | assert_process_still_running(self) -> None | Check if the underlying process is still running. | | is_connectable(self) -> bool | Establishes a socket connection to determine if the service running | on the port is accessible. | | send_remote_shutdown_command(self) -> None | Dispatch an HTTP request to the shutdown endpoint for the service in | an attempt to stop it. | | start(self) -> None | Starts the Service. | | :Exceptions: | - WebDriverException : Raised either when it can't start the service | or when it can't connect to the service | | stop(self) -> None | Stops the service. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.service.Service: | | service_url | Gets the url of the Service. | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.common.service.Service: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | path Ie = class WebDriver(selenium.webdriver.remote.webdriver.WebDriver) | Ie(options: selenium.webdriver.ie.options.Options = None, service: selenium.webdriver.ie.service.Service = None, keep_alive=True) -> None | | Controls the IEServerDriver and allows you to drive Internet | Explorer. | | Method resolution order: | WebDriver | selenium.webdriver.remote.webdriver.WebDriver | selenium.webdriver.remote.webdriver.BaseWebDriver | builtins.object | | Methods defined here: | | __init__(self, options: selenium.webdriver.ie.options.Options = None, service: selenium.webdriver.ie.service.Service = None, keep_alive=True) -> None | Creates a new instance of the Ie driver. | | Starts the service and then creates new instance of Ie driver. | | :Args: | - options - IE Options instance, providing additional IE options | - service - (Optional) service instance for managing the starting and stopping of the driver. | - keep_alive - Deprecated: Whether to configure RemoteConnection to use HTTP keep-alive. | | quit(self) -> None | Quits the driver and closes every associated window. | | :Usage: | :: | | driver.quit() | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.remote.webdriver.WebDriver: | | __enter__(self) | | __exit__(self, exc_type: Optional[Type[BaseException]], exc: Optional[BaseException], traceback: Optional[traceback]) | | __repr__(self) | Return repr(self). | | add_cookie(self, cookie_dict) -> None | Adds a cookie to your current session. | | :Args: | - cookie_dict: A dictionary object, with required keys - "name" and "value"; | optional keys - "path", "domain", "secure", "httpOnly", "expiry", "sameSite" | | :Usage: | :: | | driver.add_cookie({'name' : 'foo', 'value' : 'bar'}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/'}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/', 'secure' : True}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'sameSite' : 'Strict'}) | | add_credential(self, credential: selenium.webdriver.common.virtual_authenticator.Credential) -> None | Injects a credential into the authenticator. | | add_virtual_authenticator(self, options: selenium.webdriver.common.virtual_authenticator.VirtualAuthenticatorOptions) -> None | Adds a virtual authenticator with the given options. | | back(self) -> None | Goes one step backward in the browser history. | | :Usage: | :: | | driver.back() | | bidi_connection(self) | | close(self) -> None | Closes the current window. | | :Usage: | :: | | driver.close() | | create_web_element(self, element_id: str) -> selenium.webdriver.remote.webelement.WebElement | Creates a web element with the specified `element_id`. | | delete_all_cookies(self) -> None | Delete all cookies in the scope of the session. | | :Usage: | :: | | driver.delete_all_cookies() | | delete_cookie(self, name) -> None | Deletes a single cookie with the given name. | | :Usage: | :: | | driver.delete_cookie('my_cookie') | | delete_downloadable_files(self) -> None | Deletes all downloadable files. | | download_file(self, file_name: str, target_directory: str) -> None | Downloads a file with the specified file name to the target | directory. | | file_name: The name of the file to download. | target_directory: The path to the directory to save the downloaded file. | | execute(self, driver_command: str, params: dict = None) -> dict | Sends a command to be executed by a command.CommandExecutor. | | :Args: | - driver_command: The name of the command to execute as a string. | - params: A dictionary of named parameters to send with the command. | | :Returns: | The command's JSON response loaded into a dictionary object. | | execute_async_script(self, script: str, *args) | Asynchronously Executes JavaScript in the current window/frame. | | :Args: | - script: The JavaScript to execute. | - \*args: Any applicable arguments for your JavaScript. | | :Usage: | :: | | script = "var callback = arguments[arguments.length - 1]; " \ | "window.setTimeout(function(){ callback('timeout') }, 3000);" | driver.execute_async_script(script) | | execute_script(self, script, *args) | Synchronously Executes JavaScript in the current window/frame. | | :Args: | - script: The JavaScript to execute. | - \*args: Any applicable arguments for your JavaScript. | | :Usage: | :: | | driver.execute_script('return document.title;') | | file_detector_context(self, file_detector_class, *args, **kwargs) | Overrides the current file detector (if necessary) in limited | context. Ensures the original file detector is set afterwards. | | Example:: | | with webdriver.file_detector_context(UselessFileDetector): | someinput.send_keys('/etc/hosts') | | :Args: | - file_detector_class - Class of the desired file detector. If the class is different | from the current file_detector, then the class is instantiated with args and kwargs | and used as a file detector during the duration of the context manager. | - args - Optional arguments that get passed to the file detector class during | instantiation. | - kwargs - Keyword arguments, passed the same way as args. | | find_element(self, by='id', value: Optional[str] = None) -> selenium.webdriver.remote.webelement.WebElement | Find an element given a By strategy and locator. | | :Usage: | :: | | element = driver.find_element(By.ID, 'foo') | | :rtype: WebElement | | find_elements(self, by='id', value: Optional[str] = None) -> List[selenium.webdriver.remote.webelement.WebElement] | Find elements given a By strategy and locator. | | :Usage: | :: | | elements = driver.find_elements(By.CLASS_NAME, 'foo') | | :rtype: list of WebElement | | forward(self) -> None | Goes one step forward in the browser history. | | :Usage: | :: | | driver.forward() | | fullscreen_window(self) -> None | Invokes the window manager-specific 'full screen' operation. | | get(self, url: str) -> None | Loads a web page in the current browser session. | | get_cookie(self, name) -> Optional[Dict] | Get a single cookie by name. Returns the cookie if found, None if | not. | | :Usage: | :: | | driver.get_cookie('my_cookie') | | get_cookies(self) -> List[dict] | Returns a set of dictionaries, corresponding to cookies visible in | the current session. | | :Usage: | :: | | driver.get_cookies() | | get_credentials(self) -> List[selenium.webdriver.common.virtual_authenticator.Credential] | Returns the list of credentials owned by the authenticator. | | get_downloadable_files(self) -> dict | Retrieves the downloadable files as a map of file names and their | corresponding URLs. | | get_log(self, log_type) | Gets the log for a given log type. | | :Args: | - log_type: type of log that which will be returned | | :Usage: | :: | | driver.get_log('browser') | driver.get_log('driver') | driver.get_log('client') | driver.get_log('server') | | get_pinned_scripts(self) -> List[str] | | get_screenshot_as_base64(self) -> str | Gets the screenshot of the current window as a base64 encoded string | which is useful in embedded images in HTML. | | :Usage: | :: | | driver.get_screenshot_as_base64() | | get_screenshot_as_file(self, filename) -> bool | Saves a screenshot of the current window to a PNG image file. | Returns False if there is any IOError, else returns True. Use full | paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.get_screenshot_as_file('/Screenshots/foo.png') | | get_screenshot_as_png(self) -> bytes | Gets the screenshot of the current window as a binary data. | | :Usage: | :: | | driver.get_screenshot_as_png() | | get_window_position(self, windowHandle='current') -> dict | Gets the x,y position of the current window. | | :Usage: | :: | | driver.get_window_position() | | get_window_rect(self) -> dict | Gets the x, y coordinates of the window as well as height and width | of the current window. | | :Usage: | :: | | driver.get_window_rect() | | get_window_size(self, windowHandle: str = 'current') -> dict | Gets the width and height of the current window. | | :Usage: | :: | | driver.get_window_size() | | implicitly_wait(self, time_to_wait: float) -> None | Sets a sticky timeout to implicitly wait for an element to be found, | or a command to complete. This method only needs to be called one time | per session. To set the timeout for calls to execute_async_script, see | set_script_timeout. | | :Args: | - time_to_wait: Amount of time to wait (in seconds) | | :Usage: | :: | | driver.implicitly_wait(30) | | maximize_window(self) -> None | Maximizes the current window that webdriver is using. | | minimize_window(self) -> None | Invokes the window manager-specific 'minimize' operation. | | pin_script(self, script: str, script_key=None) -> selenium.webdriver.remote.script_key.ScriptKey | Store common javascript scripts to be executed later by a unique | hashable ID. | | print_page(self, print_options: Optional[selenium.webdriver.common.print_page_options.PrintOptions] = None) -> str | Takes PDF of the current page. | | The driver makes a best effort to return a PDF based on the | provided parameters. | | refresh(self) -> None | Refreshes the current page. | | :Usage: | :: | | driver.refresh() | | remove_all_credentials(self) -> None | Removes all credentials from the authenticator. | | remove_credential(self, credential_id: Union[str, bytearray]) -> None | Removes a credential from the authenticator. | | remove_virtual_authenticator(self) -> None | Removes a previously added virtual authenticator. | | The authenticator is no longer valid after removal, so no | methods may be called. | | save_screenshot(self, filename) -> bool | Saves a screenshot of the current window to a PNG image file. | Returns False if there is any IOError, else returns True. Use full | paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.save_screenshot('/Screenshots/foo.png') | | set_page_load_timeout(self, time_to_wait: float) -> None | Set the amount of time to wait for a page load to complete before | throwing an error. | | :Args: | - time_to_wait: The amount of time to wait | | :Usage: | :: | | driver.set_page_load_timeout(30) | | set_script_timeout(self, time_to_wait: float) -> None | Set the amount of time that the script should wait during an | execute_async_script call before throwing an error. | | :Args: | - time_to_wait: The amount of time to wait (in seconds) | | :Usage: | :: | | driver.set_script_timeout(30) | | set_user_verified(self, verified: bool) -> None | Sets whether the authenticator will simulate success or fail on user | verification. | | verified: True if the authenticator will pass user verification, False otherwise. | | set_window_position(self, x, y, windowHandle: str = 'current') -> dict | Sets the x,y position of the current window. (window.moveTo) | | :Args: | - x: the x-coordinate in pixels to set the window position | - y: the y-coordinate in pixels to set the window position | | :Usage: | :: | | driver.set_window_position(0,0) | | set_window_rect(self, x=None, y=None, width=None, height=None) -> dict | Sets the x, y coordinates of the window as well as height and width | of the current window. This method is only supported for W3C compatible | browsers; other browsers should use `set_window_position` and | `set_window_size`. | | :Usage: | :: | | driver.set_window_rect(x=10, y=10) | driver.set_window_rect(width=100, height=200) | driver.set_window_rect(x=10, y=10, width=100, height=200) | | set_window_size(self, width, height, windowHandle: str = 'current') -> None | Sets the width and height of the current window. (window.resizeTo) | | :Args: | - width: the width in pixels to set the window to | - height: the height in pixels to set the window to | | :Usage: | :: | | driver.set_window_size(800,600) | | start_client(self) | Called before starting a new session. | | This method may be overridden to define custom startup behavior. | | start_session(self, capabilities: dict) -> None | Creates a new session with the desired capabilities. | | :Args: | - capabilities - a capabilities dict to start the session with. | | stop_client(self) | Called after executing a quit command. | | This method may be overridden to define custom shutdown | behavior. | | unpin(self, script_key: selenium.webdriver.remote.script_key.ScriptKey) -> None | Remove a pinned script from storage. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.remote.webdriver.WebDriver: | | application_cache | Returns a ApplicationCache Object to interact with the browser app | cache. | | capabilities | Returns the drivers current capabilities being used. | | current_url | Gets the URL of the current page. | | :Usage: | :: | | driver.current_url | | current_window_handle | Returns the handle of the current window. | | :Usage: | :: | | driver.current_window_handle | | desired_capabilities | Returns the drivers current desired capabilities being used. | | log_types | Gets a list of the available log types. This only works with w3c | compliant browsers. | | :Usage: | :: | | driver.log_types | | mobile | | name | Returns the name of the underlying browser for this instance. | | :Usage: | :: | | name = driver.name | | page_source | Gets the source of the current page. | | :Usage: | :: | | driver.page_source | | switch_to | :Returns: | - SwitchTo: an object containing all options to switch focus into | | :Usage: | :: | | element = driver.switch_to.active_element | alert = driver.switch_to.alert | driver.switch_to.default_content() | driver.switch_to.frame('frame_name') | driver.switch_to.frame(1) | driver.switch_to.frame(driver.find_elements(By.TAG_NAME, "iframe")[0]) | driver.switch_to.parent_frame() | driver.switch_to.window('main') | | title | Returns the title of the current page. | | :Usage: | :: | | title = driver.title | | virtual_authenticator_id | Returns the id of the virtual authenticator. | | window_handles | Returns the handles of all windows within the current session. | | :Usage: | :: | | driver.window_handles | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.remote.webdriver.WebDriver: | | file_detector | | orientation | Gets the current orientation of the device. | | :Usage: | :: | | orientation = driver.orientation | | timeouts | Get all the timeouts that have been set on the current session. | | :Usage: | :: | | driver.timeouts | :rtype: Timeout | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.remote.webdriver.BaseWebDriver: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) IeOptions = class Options(selenium.webdriver.common.options.ArgOptions) | IeOptions() -> None | | Method resolution order: | Options | selenium.webdriver.common.options.ArgOptions | selenium.webdriver.common.options.BaseOptions | builtins.object | | Methods defined here: | | __init__(self) -> None | Initialize self. See help(type(self)) for accurate signature. | | add_additional_option(self, name: str, value) | Adds an additional option not yet added as a safe option for IE. | | :Args: | - name: name of the option to add | - value: value of the option to add | | to_capabilities(self) -> dict | Marshals the IE options to the correct object. | | ---------------------------------------------------------------------- | Readonly properties defined here: | | additional_options | :Returns: The additional options. | | default_capabilities | Return minimal capabilities necessary as a dictionary. | | options | :Returns: A dictionary of browser options. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | attach_to_edge_chrome | | browser_attach_timeout | | edge_executable_path | | element_scroll_behavior | | ensure_clean_session | | file_upload_dialog_timeout | | force_create_process_api | | force_shell_windows_api | | full_page_screenshot | | ignore_protected_mode_settings | | ignore_zoom_level | | initial_browser_url | | native_events | | persistent_hover | | require_window_focus | | use_legacy_file_upload_dialog_handling | | use_per_process_proxy | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | ATTACH_TO_EDGE_CHROME = 'ie.edgechromium' | | BROWSER_ATTACH_TIMEOUT = 'browserAttachTimeout' | | EDGE_EXECUTABLE_PATH = 'ie.edgepath' | | ELEMENT_SCROLL_BEHAVIOR = 'elementScrollBehavior' | | ENSURE_CLEAN_SESSION = 'ie.ensureCleanSession' | | FILE_UPLOAD_DIALOG_TIMEOUT = 'ie.fileUploadDialogTimeout' | | FORCE_CREATE_PROCESS_API = 'ie.forceCreateProcessApi' | | FORCE_SHELL_WINDOWS_API = 'ie.forceShellWindowsApi' | | FULL_PAGE_SCREENSHOT = 'ie.enableFullPageScreenshot' | | IGNORE_PROCESS_MATCH = 'ie.ignoreprocessmatch' | | IGNORE_PROTECTED_MODE_SETTINGS = 'ignoreProtectedModeSettings' | | IGNORE_ZOOM_LEVEL = 'ignoreZoomSetting' | | INITIAL_BROWSER_URL = 'initialBrowserUrl' | | KEY = 'se:ieOptions' | | NATIVE_EVENTS = 'nativeEvents' | | PERSISTENT_HOVER = 'enablePersistentHover' | | REQUIRE_WINDOW_FOCUS = 'requireWindowFocus' | | SWITCHES = 'ie.browserCommandLineSwitches' | | USE_LEGACY_FILE_UPLOAD_DIALOG_HANDLING = 'ie.useLegacyFileUploadDialog... | | USE_PER_PROCESS_PROXY = 'ie.usePerProcessProxy' | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.options.ArgOptions: | | add_argument(self, argument) | Adds an argument to the list. | | :Args: | - Sets the arguments | | ignore_local_proxy_environment_variables(self) -> None | By calling this you will ignore HTTP_PROXY and HTTPS_PROXY from | being picked up and used. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.options.ArgOptions: | | arguments | :Returns: A list of arguments needed for the browser. | | ---------------------------------------------------------------------- | Data and other attributes inherited from selenium.webdriver.common.options.ArgOptions: | | BINARY_LOCATION_ERROR = 'Binary Location Must be a String' | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.options.BaseOptions: | | enable_mobile(self, android_package: Optional[str] = None, android_activity: Optional[str] = None, device_serial: Optional[str] = None) -> None | Enables mobile browser use for browsers that support it. | | :Args: | android_activity: The name of the android package to start | | set_capability(self, name, value) -> None | Sets a capability. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.options.BaseOptions: | | capabilities | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.common.options.BaseOptions: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | accept_insecure_certs | | browser_version | | enable_downloads | | page_load_strategy | | platform_name | | proxy | | set_window_rect | | strict_file_interactability | | timeouts | | unhandled_prompt_behavior IeService = class Service(selenium.webdriver.common.service.Service) | IeService(executable_path: str = None, port: int = 0, host: Optional[str] = None, service_args: Optional[List[str]] = None, log_level: Optional[str] = None, log_output: Union[int, str, IO[Any]] = None, **kwargs) -> None | | Object that manages the starting and stopping of the IEDriver. | | Method resolution order: | Service | selenium.webdriver.common.service.Service | abc.ABC | builtins.object | | Methods defined here: | | __init__(self, executable_path: str = None, port: int = 0, host: Optional[str] = None, service_args: Optional[List[str]] = None, log_level: Optional[str] = None, log_output: Union[int, str, IO[Any]] = None, **kwargs) -> None | Creates a new instance of the Service. | | :Args: | - executable_path : Path to the IEDriver | - port : Port the service is running on | - host : IP address the service port is bound | - log_level : Level of logging of service, may be "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE". | Default is "FATAL". | - log_output: (Optional) int representation of STDOUT/DEVNULL, any IO instance or String path to file. | Default is "stdout". | | command_line_args(self) -> List[str] | A List of program arguments (excluding the executable). | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.service.Service: | | __del__(self) -> None | | assert_process_still_running(self) -> None | Check if the underlying process is still running. | | is_connectable(self) -> bool | Establishes a socket connection to determine if the service running | on the port is accessible. | | send_remote_shutdown_command(self) -> None | Dispatch an HTTP request to the shutdown endpoint for the service in | an attempt to stop it. | | start(self) -> None | Starts the Service. | | :Exceptions: | - WebDriverException : Raised either when it can't start the service | or when it can't connect to the service | | stop(self) -> None | Stops the service. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.service.Service: | | service_url | Gets the url of the Service. | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.common.service.Service: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | path class Keys(builtins.object) | Set of special keys codes. | | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | ADD = '\ue025' | | ALT = '\ue00a' | | ARROW_DOWN = '\ue015' | | ARROW_LEFT = '\ue012' | | ARROW_RIGHT = '\ue014' | | ARROW_UP = '\ue013' | | BACKSPACE = '\ue003' | | BACK_SPACE = '\ue003' | | CANCEL = '\ue001' | | CLEAR = '\ue005' | | COMMAND = '\ue03d' | | CONTROL = '\ue009' | | DECIMAL = '\ue028' | | DELETE = '\ue017' | | DIVIDE = '\ue029' | | DOWN = '\ue015' | | END = '\ue010' | | ENTER = '\ue007' | | EQUALS = '\ue019' | | ESCAPE = '\ue00c' | | F1 = '\ue031' | | F10 = '\ue03a' | | F11 = '\ue03b' | | F12 = '\ue03c' | | F2 = '\ue032' | | F3 = '\ue033' | | F4 = '\ue034' | | F5 = '\ue035' | | F6 = '\ue036' | | F7 = '\ue037' | | F8 = '\ue038' | | F9 = '\ue039' | | HELP = '\ue002' | | HOME = '\ue011' | | INSERT = '\ue016' | | LEFT = '\ue012' | | LEFT_ALT = '\ue00a' | | LEFT_CONTROL = '\ue009' | | LEFT_SHIFT = '\ue008' | | META = '\ue03d' | | MULTIPLY = '\ue024' | | NULL = '\ue000' | | NUMPAD0 = '\ue01a' | | NUMPAD1 = '\ue01b' | | NUMPAD2 = '\ue01c' | | NUMPAD3 = '\ue01d' | | NUMPAD4 = '\ue01e' | | NUMPAD5 = '\ue01f' | | NUMPAD6 = '\ue020' | | NUMPAD7 = '\ue021' | | NUMPAD8 = '\ue022' | | NUMPAD9 = '\ue023' | | PAGE_DOWN = '\ue00f' | | PAGE_UP = '\ue00e' | | PAUSE = '\ue00b' | | RETURN = '\ue006' | | RIGHT = '\ue014' | | SEMICOLON = '\ue018' | | SEPARATOR = '\ue026' | | SHIFT = '\ue008' | | SPACE = '\ue00d' | | SUBTRACT = '\ue027' | | TAB = '\ue004' | | UP = '\ue013' | | ZENKAKU_HANKAKU = '\ue040' class Proxy(builtins.object) | Proxy(raw=None) | | Proxy contains information about proxy type and necessary proxy | settings. | | Methods defined here: | | __init__(self, raw=None) | Creates a new Proxy. | | :Args: | - raw: raw proxy data. If None, default class values are used. | | to_capabilities(self) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | auto_detect | | ftp_proxy | | http_proxy | | no_proxy | | proxy_autoconfig_url | | proxy_type | Returns proxy type as `ProxyType`. | | socks_password | | socks_proxy | | socks_username | | socks_version | | ssl_proxy | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | autodetect = False | | ftpProxy = '' | | httpProxy = '' | | noProxy = '' | | proxyAutoconfigUrl = '' | | proxyType = {'ff_value': 6, 'string': 'UNSPECIFIED'} | | socksPassword = '' | | socksProxy = '' | | socksUsername = '' | | socksVersion = None | | sslProxy = '' Remote = class WebDriver(BaseWebDriver) | Remote(command_executor='http://127.0.0.1:4444', keep_alive=True, file_detector=None, options: Union[selenium.webdriver.common.options.BaseOptions, List[selenium.webdriver.common.options.BaseOptions]] = None) -> None | | Controls a browser by sending commands to a remote server. This server | is expected to be running the WebDriver wire protocol as defined at | https://www.selenium.dev/documentation/legacy/json_wire_protocol/. | | :Attributes: | - session_id - String ID of the browser session started and controlled by this WebDriver. | - capabilities - Dictionary of effective capabilities of this browser session as returned | by the remote server. See https://www.selenium.dev/documentation/legacy/desired_capabilities/ | - command_executor - remote_connection.RemoteConnection object used to execute commands. | - error_handler - errorhandler.ErrorHandler object used to handle errors. | | Method resolution order: | WebDriver | BaseWebDriver | builtins.object | | Methods defined here: | | __enter__(self) | | __exit__(self, exc_type: Optional[Type[BaseException]], exc: Optional[BaseException], traceback: Optional[traceback]) | | __init__(self, command_executor='http://127.0.0.1:4444', keep_alive=True, file_detector=None, options: Union[selenium.webdriver.common.options.BaseOptions, List[selenium.webdriver.common.options.BaseOptions]] = None) -> None | Create a new driver that will issue commands using the wire | protocol. | | :Args: | - command_executor - Either a string representing URL of the remote server or a custom | remote_connection.RemoteConnection object. Defaults to 'http://127.0.0.1:4444/wd/hub'. | - keep_alive - Whether to configure remote_connection.RemoteConnection to use | HTTP keep-alive. Defaults to True. | - file_detector - Pass custom file detector object during instantiation. If None, | then default LocalFileDetector() will be used. | - options - instance of a driver options.Options class | | __repr__(self) | Return repr(self). | | add_cookie(self, cookie_dict) -> None | Adds a cookie to your current session. | | :Args: | - cookie_dict: A dictionary object, with required keys - "name" and "value"; | optional keys - "path", "domain", "secure", "httpOnly", "expiry", "sameSite" | | :Usage: | :: | | driver.add_cookie({'name' : 'foo', 'value' : 'bar'}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/'}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/', 'secure' : True}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'sameSite' : 'Strict'}) | | add_credential(self, credential: selenium.webdriver.common.virtual_authenticator.Credential) -> None | Injects a credential into the authenticator. | | add_virtual_authenticator(self, options: selenium.webdriver.common.virtual_authenticator.VirtualAuthenticatorOptions) -> None | Adds a virtual authenticator with the given options. | | back(self) -> None | Goes one step backward in the browser history. | | :Usage: | :: | | driver.back() | | bidi_connection(self) | | close(self) -> None | Closes the current window. | | :Usage: | :: | | driver.close() | | create_web_element(self, element_id: str) -> selenium.webdriver.remote.webelement.WebElement | Creates a web element with the specified `element_id`. | | delete_all_cookies(self) -> None | Delete all cookies in the scope of the session. | | :Usage: | :: | | driver.delete_all_cookies() | | delete_cookie(self, name) -> None | Deletes a single cookie with the given name. | | :Usage: | :: | | driver.delete_cookie('my_cookie') | | delete_downloadable_files(self) -> None | Deletes all downloadable files. | | download_file(self, file_name: str, target_directory: str) -> None | Downloads a file with the specified file name to the target | directory. | | file_name: The name of the file to download. | target_directory: The path to the directory to save the downloaded file. | | execute(self, driver_command: str, params: dict = None) -> dict | Sends a command to be executed by a command.CommandExecutor. | | :Args: | - driver_command: The name of the command to execute as a string. | - params: A dictionary of named parameters to send with the command. | | :Returns: | The command's JSON response loaded into a dictionary object. | | execute_async_script(self, script: str, *args) | Asynchronously Executes JavaScript in the current window/frame. | | :Args: | - script: The JavaScript to execute. | - \*args: Any applicable arguments for your JavaScript. | | :Usage: | :: | | script = "var callback = arguments[arguments.length - 1]; " \ | "window.setTimeout(function(){ callback('timeout') }, 3000);" | driver.execute_async_script(script) | | execute_script(self, script, *args) | Synchronously Executes JavaScript in the current window/frame. | | :Args: | - script: The JavaScript to execute. | - \*args: Any applicable arguments for your JavaScript. | | :Usage: | :: | | driver.execute_script('return document.title;') | | file_detector_context(self, file_detector_class, *args, **kwargs) | Overrides the current file detector (if necessary) in limited | context. Ensures the original file detector is set afterwards. | | Example:: | | with webdriver.file_detector_context(UselessFileDetector): | someinput.send_keys('/etc/hosts') | | :Args: | - file_detector_class - Class of the desired file detector. If the class is different | from the current file_detector, then the class is instantiated with args and kwargs | and used as a file detector during the duration of the context manager. | - args - Optional arguments that get passed to the file detector class during | instantiation. | - kwargs - Keyword arguments, passed the same way as args. | | find_element(self, by='id', value: Optional[str] = None) -> selenium.webdriver.remote.webelement.WebElement | Find an element given a By strategy and locator. | | :Usage: | :: | | element = driver.find_element(By.ID, 'foo') | | :rtype: WebElement | | find_elements(self, by='id', value: Optional[str] = None) -> List[selenium.webdriver.remote.webelement.WebElement] | Find elements given a By strategy and locator. | | :Usage: | :: | | elements = driver.find_elements(By.CLASS_NAME, 'foo') | | :rtype: list of WebElement | | forward(self) -> None | Goes one step forward in the browser history. | | :Usage: | :: | | driver.forward() | | fullscreen_window(self) -> None | Invokes the window manager-specific 'full screen' operation. | | get(self, url: str) -> None | Loads a web page in the current browser session. | | get_cookie(self, name) -> Optional[Dict] | Get a single cookie by name. Returns the cookie if found, None if | not. | | :Usage: | :: | | driver.get_cookie('my_cookie') | | get_cookies(self) -> List[dict] | Returns a set of dictionaries, corresponding to cookies visible in | the current session. | | :Usage: | :: | | driver.get_cookies() | | get_credentials(self) -> List[selenium.webdriver.common.virtual_authenticator.Credential] | Returns the list of credentials owned by the authenticator. | | get_downloadable_files(self) -> dict | Retrieves the downloadable files as a map of file names and their | corresponding URLs. | | get_log(self, log_type) | Gets the log for a given log type. | | :Args: | - log_type: type of log that which will be returned | | :Usage: | :: | | driver.get_log('browser') | driver.get_log('driver') | driver.get_log('client') | driver.get_log('server') | | get_pinned_scripts(self) -> List[str] | | get_screenshot_as_base64(self) -> str | Gets the screenshot of the current window as a base64 encoded string | which is useful in embedded images in HTML. | | :Usage: | :: | | driver.get_screenshot_as_base64() | | get_screenshot_as_file(self, filename) -> bool | Saves a screenshot of the current window to a PNG image file. | Returns False if there is any IOError, else returns True. Use full | paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.get_screenshot_as_file('/Screenshots/foo.png') | | get_screenshot_as_png(self) -> bytes | Gets the screenshot of the current window as a binary data. | | :Usage: | :: | | driver.get_screenshot_as_png() | | get_window_position(self, windowHandle='current') -> dict | Gets the x,y position of the current window. | | :Usage: | :: | | driver.get_window_position() | | get_window_rect(self) -> dict | Gets the x, y coordinates of the window as well as height and width | of the current window. | | :Usage: | :: | | driver.get_window_rect() | | get_window_size(self, windowHandle: str = 'current') -> dict | Gets the width and height of the current window. | | :Usage: | :: | | driver.get_window_size() | | implicitly_wait(self, time_to_wait: float) -> None | Sets a sticky timeout to implicitly wait for an element to be found, | or a command to complete. This method only needs to be called one time | per session. To set the timeout for calls to execute_async_script, see | set_script_timeout. | | :Args: | - time_to_wait: Amount of time to wait (in seconds) | | :Usage: | :: | | driver.implicitly_wait(30) | | maximize_window(self) -> None | Maximizes the current window that webdriver is using. | | minimize_window(self) -> None | Invokes the window manager-specific 'minimize' operation. | | pin_script(self, script: str, script_key=None) -> selenium.webdriver.remote.script_key.ScriptKey | Store common javascript scripts to be executed later by a unique | hashable ID. | | print_page(self, print_options: Optional[selenium.webdriver.common.print_page_options.PrintOptions] = None) -> str | Takes PDF of the current page. | | The driver makes a best effort to return a PDF based on the | provided parameters. | | quit(self) -> None | Quits the driver and closes every associated window. | | :Usage: | :: | | driver.quit() | | refresh(self) -> None | Refreshes the current page. | | :Usage: | :: | | driver.refresh() | | remove_all_credentials(self) -> None | Removes all credentials from the authenticator. | | remove_credential(self, credential_id: Union[str, bytearray]) -> None | Removes a credential from the authenticator. | | remove_virtual_authenticator(self) -> None | Removes a previously added virtual authenticator. | | The authenticator is no longer valid after removal, so no | methods may be called. | | save_screenshot(self, filename) -> bool | Saves a screenshot of the current window to a PNG image file. | Returns False if there is any IOError, else returns True. Use full | paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.save_screenshot('/Screenshots/foo.png') | | set_page_load_timeout(self, time_to_wait: float) -> None | Set the amount of time to wait for a page load to complete before | throwing an error. | | :Args: | - time_to_wait: The amount of time to wait | | :Usage: | :: | | driver.set_page_load_timeout(30) | | set_script_timeout(self, time_to_wait: float) -> None | Set the amount of time that the script should wait during an | execute_async_script call before throwing an error. | | :Args: | - time_to_wait: The amount of time to wait (in seconds) | | :Usage: | :: | | driver.set_script_timeout(30) | | set_user_verified(self, verified: bool) -> None | Sets whether the authenticator will simulate success or fail on user | verification. | | verified: True if the authenticator will pass user verification, False otherwise. | | set_window_position(self, x, y, windowHandle: str = 'current') -> dict | Sets the x,y position of the current window. (window.moveTo) | | :Args: | - x: the x-coordinate in pixels to set the window position | - y: the y-coordinate in pixels to set the window position | | :Usage: | :: | | driver.set_window_position(0,0) | | set_window_rect(self, x=None, y=None, width=None, height=None) -> dict | Sets the x, y coordinates of the window as well as height and width | of the current window. This method is only supported for W3C compatible | browsers; other browsers should use `set_window_position` and | `set_window_size`. | | :Usage: | :: | | driver.set_window_rect(x=10, y=10) | driver.set_window_rect(width=100, height=200) | driver.set_window_rect(x=10, y=10, width=100, height=200) | | set_window_size(self, width, height, windowHandle: str = 'current') -> None | Sets the width and height of the current window. (window.resizeTo) | | :Args: | - width: the width in pixels to set the window to | - height: the height in pixels to set the window to | | :Usage: | :: | | driver.set_window_size(800,600) | | start_client(self) | Called before starting a new session. | | This method may be overridden to define custom startup behavior. | | start_session(self, capabilities: dict) -> None | Creates a new session with the desired capabilities. | | :Args: | - capabilities - a capabilities dict to start the session with. | | stop_client(self) | Called after executing a quit command. | | This method may be overridden to define custom shutdown | behavior. | | unpin(self, script_key: selenium.webdriver.remote.script_key.ScriptKey) -> None | Remove a pinned script from storage. | | ---------------------------------------------------------------------- | Readonly properties defined here: | | application_cache | Returns a ApplicationCache Object to interact with the browser app | cache. | | capabilities | Returns the drivers current capabilities being used. | | current_url | Gets the URL of the current page. | | :Usage: | :: | | driver.current_url | | current_window_handle | Returns the handle of the current window. | | :Usage: | :: | | driver.current_window_handle | | desired_capabilities | Returns the drivers current desired capabilities being used. | | log_types | Gets a list of the available log types. This only works with w3c | compliant browsers. | | :Usage: | :: | | driver.log_types | | mobile | | name | Returns the name of the underlying browser for this instance. | | :Usage: | :: | | name = driver.name | | page_source | Gets the source of the current page. | | :Usage: | :: | | driver.page_source | | switch_to | :Returns: | - SwitchTo: an object containing all options to switch focus into | | :Usage: | :: | | element = driver.switch_to.active_element | alert = driver.switch_to.alert | driver.switch_to.default_content() | driver.switch_to.frame('frame_name') | driver.switch_to.frame(1) | driver.switch_to.frame(driver.find_elements(By.TAG_NAME, "iframe")[0]) | driver.switch_to.parent_frame() | driver.switch_to.window('main') | | title | Returns the title of the current page. | | :Usage: | :: | | title = driver.title | | virtual_authenticator_id | Returns the id of the virtual authenticator. | | window_handles | Returns the handles of all windows within the current session. | | :Usage: | :: | | driver.window_handles | | ---------------------------------------------------------------------- | Data descriptors defined here: | | file_detector | | orientation | Gets the current orientation of the device. | | :Usage: | :: | | orientation = driver.orientation | | timeouts | Get all the timeouts that have been set on the current session. | | :Usage: | :: | | driver.timeouts | :rtype: Timeout | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Data descriptors inherited from BaseWebDriver: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) Safari = class WebDriver(selenium.webdriver.remote.webdriver.WebDriver) | Safari(reuse_service=False, keep_alive=True, options: selenium.webdriver.safari.options.Options = None, service: selenium.webdriver.safari.service.Service = None) -> None | | Controls the SafariDriver and allows you to drive the browser. | | Method resolution order: | WebDriver | selenium.webdriver.remote.webdriver.WebDriver | selenium.webdriver.remote.webdriver.BaseWebDriver | builtins.object | | Methods defined here: | | __init__(self, reuse_service=False, keep_alive=True, options: selenium.webdriver.safari.options.Options = None, service: selenium.webdriver.safari.service.Service = None) -> None | Creates a new Safari driver instance and launches or finds a running | safaridriver service. | | :Args: | - reuse_service - If True, do not spawn a safaridriver instance; instead, connect to an already-running service that was launched externally. | - keep_alive - Whether to configure SafariRemoteConnection to use | HTTP keep-alive. Defaults to True. | - options - Instance of ``options.Options``. | - service - Service object for handling the browser driver if you need to pass extra details | | debug(self) | # First available in Safari 11.1 and Safari Technology Preview 42. | | get_permission(self, permission) | # First available in Safari 11.1 and Safari Technology Preview 41. | | quit(self) | Closes the browser and shuts down the SafariDriver executable that | is started when starting the SafariDriver. | | set_permission(self, permission, value) | # First available in Safari 11.1 and Safari Technology Preview 41. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.remote.webdriver.WebDriver: | | __enter__(self) | | __exit__(self, exc_type: Optional[Type[BaseException]], exc: Optional[BaseException], traceback: Optional[traceback]) | | __repr__(self) | Return repr(self). | | add_cookie(self, cookie_dict) -> None | Adds a cookie to your current session. | | :Args: | - cookie_dict: A dictionary object, with required keys - "name" and "value"; | optional keys - "path", "domain", "secure", "httpOnly", "expiry", "sameSite" | | :Usage: | :: | | driver.add_cookie({'name' : 'foo', 'value' : 'bar'}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/'}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/', 'secure' : True}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'sameSite' : 'Strict'}) | | add_credential(self, credential: selenium.webdriver.common.virtual_authenticator.Credential) -> None | Injects a credential into the authenticator. | | add_virtual_authenticator(self, options: selenium.webdriver.common.virtual_authenticator.VirtualAuthenticatorOptions) -> None | Adds a virtual authenticator with the given options. | | back(self) -> None | Goes one step backward in the browser history. | | :Usage: | :: | | driver.back() | | bidi_connection(self) | | close(self) -> None | Closes the current window. | | :Usage: | :: | | driver.close() | | create_web_element(self, element_id: str) -> selenium.webdriver.remote.webelement.WebElement | Creates a web element with the specified `element_id`. | | delete_all_cookies(self) -> None | Delete all cookies in the scope of the session. | | :Usage: | :: | | driver.delete_all_cookies() | | delete_cookie(self, name) -> None | Deletes a single cookie with the given name. | | :Usage: | :: | | driver.delete_cookie('my_cookie') | | delete_downloadable_files(self) -> None | Deletes all downloadable files. | | download_file(self, file_name: str, target_directory: str) -> None | Downloads a file with the specified file name to the target | directory. | | file_name: The name of the file to download. | target_directory: The path to the directory to save the downloaded file. | | execute(self, driver_command: str, params: dict = None) -> dict | Sends a command to be executed by a command.CommandExecutor. | | :Args: | - driver_command: The name of the command to execute as a string. | - params: A dictionary of named parameters to send with the command. | | :Returns: | The command's JSON response loaded into a dictionary object. | | execute_async_script(self, script: str, *args) | Asynchronously Executes JavaScript in the current window/frame. | | :Args: | - script: The JavaScript to execute. | - \*args: Any applicable arguments for your JavaScript. | | :Usage: | :: | | script = "var callback = arguments[arguments.length - 1]; " \ | "window.setTimeout(function(){ callback('timeout') }, 3000);" | driver.execute_async_script(script) | | execute_script(self, script, *args) | Synchronously Executes JavaScript in the current window/frame. | | :Args: | - script: The JavaScript to execute. | - \*args: Any applicable arguments for your JavaScript. | | :Usage: | :: | | driver.execute_script('return document.title;') | | file_detector_context(self, file_detector_class, *args, **kwargs) | Overrides the current file detector (if necessary) in limited | context. Ensures the original file detector is set afterwards. | | Example:: | | with webdriver.file_detector_context(UselessFileDetector): | someinput.send_keys('/etc/hosts') | | :Args: | - file_detector_class - Class of the desired file detector. If the class is different | from the current file_detector, then the class is instantiated with args and kwargs | and used as a file detector during the duration of the context manager. | - args - Optional arguments that get passed to the file detector class during | instantiation. | - kwargs - Keyword arguments, passed the same way as args. | | find_element(self, by='id', value: Optional[str] = None) -> selenium.webdriver.remote.webelement.WebElement | Find an element given a By strategy and locator. | | :Usage: | :: | | element = driver.find_element(By.ID, 'foo') | | :rtype: WebElement | | find_elements(self, by='id', value: Optional[str] = None) -> List[selenium.webdriver.remote.webelement.WebElement] | Find elements given a By strategy and locator. | | :Usage: | :: | | elements = driver.find_elements(By.CLASS_NAME, 'foo') | | :rtype: list of WebElement | | forward(self) -> None | Goes one step forward in the browser history. | | :Usage: | :: | | driver.forward() | | fullscreen_window(self) -> None | Invokes the window manager-specific 'full screen' operation. | | get(self, url: str) -> None | Loads a web page in the current browser session. | | get_cookie(self, name) -> Optional[Dict] | Get a single cookie by name. Returns the cookie if found, None if | not. | | :Usage: | :: | | driver.get_cookie('my_cookie') | | get_cookies(self) -> List[dict] | Returns a set of dictionaries, corresponding to cookies visible in | the current session. | | :Usage: | :: | | driver.get_cookies() | | get_credentials(self) -> List[selenium.webdriver.common.virtual_authenticator.Credential] | Returns the list of credentials owned by the authenticator. | | get_downloadable_files(self) -> dict | Retrieves the downloadable files as a map of file names and their | corresponding URLs. | | get_log(self, log_type) | Gets the log for a given log type. | | :Args: | - log_type: type of log that which will be returned | | :Usage: | :: | | driver.get_log('browser') | driver.get_log('driver') | driver.get_log('client') | driver.get_log('server') | | get_pinned_scripts(self) -> List[str] | | get_screenshot_as_base64(self) -> str | Gets the screenshot of the current window as a base64 encoded string | which is useful in embedded images in HTML. | | :Usage: | :: | | driver.get_screenshot_as_base64() | | get_screenshot_as_file(self, filename) -> bool | Saves a screenshot of the current window to a PNG image file. | Returns False if there is any IOError, else returns True. Use full | paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.get_screenshot_as_file('/Screenshots/foo.png') | | get_screenshot_as_png(self) -> bytes | Gets the screenshot of the current window as a binary data. | | :Usage: | :: | | driver.get_screenshot_as_png() | | get_window_position(self, windowHandle='current') -> dict | Gets the x,y position of the current window. | | :Usage: | :: | | driver.get_window_position() | | get_window_rect(self) -> dict | Gets the x, y coordinates of the window as well as height and width | of the current window. | | :Usage: | :: | | driver.get_window_rect() | | get_window_size(self, windowHandle: str = 'current') -> dict | Gets the width and height of the current window. | | :Usage: | :: | | driver.get_window_size() | | implicitly_wait(self, time_to_wait: float) -> None | Sets a sticky timeout to implicitly wait for an element to be found, | or a command to complete. This method only needs to be called one time | per session. To set the timeout for calls to execute_async_script, see | set_script_timeout. | | :Args: | - time_to_wait: Amount of time to wait (in seconds) | | :Usage: | :: | | driver.implicitly_wait(30) | | maximize_window(self) -> None | Maximizes the current window that webdriver is using. | | minimize_window(self) -> None | Invokes the window manager-specific 'minimize' operation. | | pin_script(self, script: str, script_key=None) -> selenium.webdriver.remote.script_key.ScriptKey | Store common javascript scripts to be executed later by a unique | hashable ID. | | print_page(self, print_options: Optional[selenium.webdriver.common.print_page_options.PrintOptions] = None) -> str | Takes PDF of the current page. | | The driver makes a best effort to return a PDF based on the | provided parameters. | | refresh(self) -> None | Refreshes the current page. | | :Usage: | :: | | driver.refresh() | | remove_all_credentials(self) -> None | Removes all credentials from the authenticator. | | remove_credential(self, credential_id: Union[str, bytearray]) -> None | Removes a credential from the authenticator. | | remove_virtual_authenticator(self) -> None | Removes a previously added virtual authenticator. | | The authenticator is no longer valid after removal, so no | methods may be called. | | save_screenshot(self, filename) -> bool | Saves a screenshot of the current window to a PNG image file. | Returns False if there is any IOError, else returns True. Use full | paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.save_screenshot('/Screenshots/foo.png') | | set_page_load_timeout(self, time_to_wait: float) -> None | Set the amount of time to wait for a page load to complete before | throwing an error. | | :Args: | - time_to_wait: The amount of time to wait | | :Usage: | :: | | driver.set_page_load_timeout(30) | | set_script_timeout(self, time_to_wait: float) -> None | Set the amount of time that the script should wait during an | execute_async_script call before throwing an error. | | :Args: | - time_to_wait: The amount of time to wait (in seconds) | | :Usage: | :: | | driver.set_script_timeout(30) | | set_user_verified(self, verified: bool) -> None | Sets whether the authenticator will simulate success or fail on user | verification. | | verified: True if the authenticator will pass user verification, False otherwise. | | set_window_position(self, x, y, windowHandle: str = 'current') -> dict | Sets the x,y position of the current window. (window.moveTo) | | :Args: | - x: the x-coordinate in pixels to set the window position | - y: the y-coordinate in pixels to set the window position | | :Usage: | :: | | driver.set_window_position(0,0) | | set_window_rect(self, x=None, y=None, width=None, height=None) -> dict | Sets the x, y coordinates of the window as well as height and width | of the current window. This method is only supported for W3C compatible | browsers; other browsers should use `set_window_position` and | `set_window_size`. | | :Usage: | :: | | driver.set_window_rect(x=10, y=10) | driver.set_window_rect(width=100, height=200) | driver.set_window_rect(x=10, y=10, width=100, height=200) | | set_window_size(self, width, height, windowHandle: str = 'current') -> None | Sets the width and height of the current window. (window.resizeTo) | | :Args: | - width: the width in pixels to set the window to | - height: the height in pixels to set the window to | | :Usage: | :: | | driver.set_window_size(800,600) | | start_client(self) | Called before starting a new session. | | This method may be overridden to define custom startup behavior. | | start_session(self, capabilities: dict) -> None | Creates a new session with the desired capabilities. | | :Args: | - capabilities - a capabilities dict to start the session with. | | stop_client(self) | Called after executing a quit command. | | This method may be overridden to define custom shutdown | behavior. | | unpin(self, script_key: selenium.webdriver.remote.script_key.ScriptKey) -> None | Remove a pinned script from storage. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.remote.webdriver.WebDriver: | | application_cache | Returns a ApplicationCache Object to interact with the browser app | cache. | | capabilities | Returns the drivers current capabilities being used. | | current_url | Gets the URL of the current page. | | :Usage: | :: | | driver.current_url | | current_window_handle | Returns the handle of the current window. | | :Usage: | :: | | driver.current_window_handle | | desired_capabilities | Returns the drivers current desired capabilities being used. | | log_types | Gets a list of the available log types. This only works with w3c | compliant browsers. | | :Usage: | :: | | driver.log_types | | mobile | | name | Returns the name of the underlying browser for this instance. | | :Usage: | :: | | name = driver.name | | page_source | Gets the source of the current page. | | :Usage: | :: | | driver.page_source | | switch_to | :Returns: | - SwitchTo: an object containing all options to switch focus into | | :Usage: | :: | | element = driver.switch_to.active_element | alert = driver.switch_to.alert | driver.switch_to.default_content() | driver.switch_to.frame('frame_name') | driver.switch_to.frame(1) | driver.switch_to.frame(driver.find_elements(By.TAG_NAME, "iframe")[0]) | driver.switch_to.parent_frame() | driver.switch_to.window('main') | | title | Returns the title of the current page. | | :Usage: | :: | | title = driver.title | | virtual_authenticator_id | Returns the id of the virtual authenticator. | | window_handles | Returns the handles of all windows within the current session. | | :Usage: | :: | | driver.window_handles | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.remote.webdriver.WebDriver: | | file_detector | | orientation | Gets the current orientation of the device. | | :Usage: | :: | | orientation = driver.orientation | | timeouts | Get all the timeouts that have been set on the current session. | | :Usage: | :: | | driver.timeouts | :rtype: Timeout | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.remote.webdriver.BaseWebDriver: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) SafariOptions = class Options(selenium.webdriver.common.options.ArgOptions) | SafariOptions() -> None | | Method resolution order: | Options | selenium.webdriver.common.options.ArgOptions | selenium.webdriver.common.options.BaseOptions | builtins.object | | Readonly properties defined here: | | default_capabilities | Return minimal capabilities necessary as a dictionary. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | automatic_inspection | | automatic_profiling | | use_technology_preview | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | AUTOMATIC_INSPECTION = 'safari:automaticInspection' | | AUTOMATIC_PROFILING = 'safari:automaticProfiling' | | SAFARI_TECH_PREVIEW = 'Safari Technology Preview' | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.options.ArgOptions: | | __init__(self) -> None | Initialize self. See help(type(self)) for accurate signature. | | add_argument(self, argument) | Adds an argument to the list. | | :Args: | - Sets the arguments | | ignore_local_proxy_environment_variables(self) -> None | By calling this you will ignore HTTP_PROXY and HTTPS_PROXY from | being picked up and used. | | to_capabilities(self) | Convert options into capabilities dictionary. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.options.ArgOptions: | | arguments | :Returns: A list of arguments needed for the browser. | | ---------------------------------------------------------------------- | Data and other attributes inherited from selenium.webdriver.common.options.ArgOptions: | | BINARY_LOCATION_ERROR = 'Binary Location Must be a String' | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.options.BaseOptions: | | enable_mobile(self, android_package: Optional[str] = None, android_activity: Optional[str] = None, device_serial: Optional[str] = None) -> None | Enables mobile browser use for browsers that support it. | | :Args: | android_activity: The name of the android package to start | | set_capability(self, name, value) -> None | Sets a capability. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.options.BaseOptions: | | capabilities | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.common.options.BaseOptions: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | accept_insecure_certs | | browser_version | | enable_downloads | | page_load_strategy | | platform_name | | proxy | | set_window_rect | | strict_file_interactability | | timeouts | | unhandled_prompt_behavior SafariService = class Service(selenium.webdriver.common.service.Service) | SafariService(executable_path: str = None, port: int = 0, quiet: bool = None, service_args: Optional[List[str]] = None, env: Optional[Mapping[str, str]] = None, reuse_service=False, **kwargs) -> None | | A Service class that is responsible for the starting and stopping of | `safaridriver` This is only supported on MAC OSX. | | :param executable_path: install path of the safaridriver executable, defaults to `/usr/bin/safaridriver`. | :param port: Port for the service to run on, defaults to 0 where the operating system will decide. | :param quiet: (Deprecated) Suppress driver stdout & stderr, redirects to os.devnull if enabled. | :param service_args: (Optional) List of args to be passed to the subprocess when launching the executable. | :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. | | Method resolution order: | Service | selenium.webdriver.common.service.Service | abc.ABC | builtins.object | | Methods defined here: | | __init__(self, executable_path: str = None, port: int = 0, quiet: bool = None, service_args: Optional[List[str]] = None, env: Optional[Mapping[str, str]] = None, reuse_service=False, **kwargs) -> None | Initialize self. See help(type(self)) for accurate signature. | | command_line_args(self) -> List[str] | A List of program arguments (excluding the executable). | | ---------------------------------------------------------------------- | Readonly properties defined here: | | service_url | Gets the url of the SafariDriver Service. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | reuse_service | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.service.Service: | | __del__(self) -> None | | assert_process_still_running(self) -> None | Check if the underlying process is still running. | | is_connectable(self) -> bool | Establishes a socket connection to determine if the service running | on the port is accessible. | | send_remote_shutdown_command(self) -> None | Dispatch an HTTP request to the shutdown endpoint for the service in | an attempt to stop it. | | start(self) -> None | Starts the Service. | | :Exceptions: | - WebDriverException : Raised either when it can't start the service | or when it can't connect to the service | | stop(self) -> None | Stops the service. | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.common.service.Service: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | path WPEWebKit = class WebDriver(selenium.webdriver.remote.webdriver.WebDriver) | WPEWebKit(executable_path='WPEWebDriver', port=0, options=None, desired_capabilities={'browserName': 'MiniBrowser', 'version': '', 'platform': 'ANY'}, service_log_path=None) | | Controls the WPEWebKitDriver and allows you to drive the browser. | | Method resolution order: | WebDriver | selenium.webdriver.remote.webdriver.WebDriver | selenium.webdriver.remote.webdriver.BaseWebDriver | builtins.object | | Methods defined here: | | __init__(self, executable_path='WPEWebDriver', port=0, options=None, desired_capabilities={'browserName': 'MiniBrowser', 'version': '', 'platform': 'ANY'}, service_log_path=None) | Creates a new instance of the WPEWebKit driver. | | Starts the service and then creates new instance of WPEWebKit Driver. | | :Args: | - executable_path : path to the executable. If the default is used it assumes the executable is in the $PATH. | - port : port you would like the service to run, if left as 0, a free port will be found. | - options : an instance of WPEWebKitOptions | - desired_capabilities : Dictionary object with desired capabilities | - service_log_path : Path to write service stdout and stderr output. | | quit(self) | Closes the browser and shuts down the WPEWebKitDriver executable | that is started when starting the WPEWebKitDriver. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.remote.webdriver.WebDriver: | | __enter__(self) | | __exit__(self, exc_type: Optional[Type[BaseException]], exc: Optional[BaseException], traceback: Optional[traceback]) | | __repr__(self) | Return repr(self). | | add_cookie(self, cookie_dict) -> None | Adds a cookie to your current session. | | :Args: | - cookie_dict: A dictionary object, with required keys - "name" and "value"; | optional keys - "path", "domain", "secure", "httpOnly", "expiry", "sameSite" | | :Usage: | :: | | driver.add_cookie({'name' : 'foo', 'value' : 'bar'}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/'}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/', 'secure' : True}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'sameSite' : 'Strict'}) | | add_credential(self, credential: selenium.webdriver.common.virtual_authenticator.Credential) -> None | Injects a credential into the authenticator. | | add_virtual_authenticator(self, options: selenium.webdriver.common.virtual_authenticator.VirtualAuthenticatorOptions) -> None | Adds a virtual authenticator with the given options. | | back(self) -> None | Goes one step backward in the browser history. | | :Usage: | :: | | driver.back() | | bidi_connection(self) | | close(self) -> None | Closes the current window. | | :Usage: | :: | | driver.close() | | create_web_element(self, element_id: str) -> selenium.webdriver.remote.webelement.WebElement | Creates a web element with the specified `element_id`. | | delete_all_cookies(self) -> None | Delete all cookies in the scope of the session. | | :Usage: | :: | | driver.delete_all_cookies() | | delete_cookie(self, name) -> None | Deletes a single cookie with the given name. | | :Usage: | :: | | driver.delete_cookie('my_cookie') | | delete_downloadable_files(self) -> None | Deletes all downloadable files. | | download_file(self, file_name: str, target_directory: str) -> None | Downloads a file with the specified file name to the target | directory. | | file_name: The name of the file to download. | target_directory: The path to the directory to save the downloaded file. | | execute(self, driver_command: str, params: dict = None) -> dict | Sends a command to be executed by a command.CommandExecutor. | | :Args: | - driver_command: The name of the command to execute as a string. | - params: A dictionary of named parameters to send with the command. | | :Returns: | The command's JSON response loaded into a dictionary object. | | execute_async_script(self, script: str, *args) | Asynchronously Executes JavaScript in the current window/frame. | | :Args: | - script: The JavaScript to execute. | - \*args: Any applicable arguments for your JavaScript. | | :Usage: | :: | | script = "var callback = arguments[arguments.length - 1]; " \ | "window.setTimeout(function(){ callback('timeout') }, 3000);" | driver.execute_async_script(script) | | execute_script(self, script, *args) | Synchronously Executes JavaScript in the current window/frame. | | :Args: | - script: The JavaScript to execute. | - \*args: Any applicable arguments for your JavaScript. | | :Usage: | :: | | driver.execute_script('return document.title;') | | file_detector_context(self, file_detector_class, *args, **kwargs) | Overrides the current file detector (if necessary) in limited | context. Ensures the original file detector is set afterwards. | | Example:: | | with webdriver.file_detector_context(UselessFileDetector): | someinput.send_keys('/etc/hosts') | | :Args: | - file_detector_class - Class of the desired file detector. If the class is different | from the current file_detector, then the class is instantiated with args and kwargs | and used as a file detector during the duration of the context manager. | - args - Optional arguments that get passed to the file detector class during | instantiation. | - kwargs - Keyword arguments, passed the same way as args. | | find_element(self, by='id', value: Optional[str] = None) -> selenium.webdriver.remote.webelement.WebElement | Find an element given a By strategy and locator. | | :Usage: | :: | | element = driver.find_element(By.ID, 'foo') | | :rtype: WebElement | | find_elements(self, by='id', value: Optional[str] = None) -> List[selenium.webdriver.remote.webelement.WebElement] | Find elements given a By strategy and locator. | | :Usage: | :: | | elements = driver.find_elements(By.CLASS_NAME, 'foo') | | :rtype: list of WebElement | | forward(self) -> None | Goes one step forward in the browser history. | | :Usage: | :: | | driver.forward() | | fullscreen_window(self) -> None | Invokes the window manager-specific 'full screen' operation. | | get(self, url: str) -> None | Loads a web page in the current browser session. | | get_cookie(self, name) -> Optional[Dict] | Get a single cookie by name. Returns the cookie if found, None if | not. | | :Usage: | :: | | driver.get_cookie('my_cookie') | | get_cookies(self) -> List[dict] | Returns a set of dictionaries, corresponding to cookies visible in | the current session. | | :Usage: | :: | | driver.get_cookies() | | get_credentials(self) -> List[selenium.webdriver.common.virtual_authenticator.Credential] | Returns the list of credentials owned by the authenticator. | | get_downloadable_files(self) -> dict | Retrieves the downloadable files as a map of file names and their | corresponding URLs. | | get_log(self, log_type) | Gets the log for a given log type. | | :Args: | - log_type: type of log that which will be returned | | :Usage: | :: | | driver.get_log('browser') | driver.get_log('driver') | driver.get_log('client') | driver.get_log('server') | | get_pinned_scripts(self) -> List[str] | | get_screenshot_as_base64(self) -> str | Gets the screenshot of the current window as a base64 encoded string | which is useful in embedded images in HTML. | | :Usage: | :: | | driver.get_screenshot_as_base64() | | get_screenshot_as_file(self, filename) -> bool | Saves a screenshot of the current window to a PNG image file. | Returns False if there is any IOError, else returns True. Use full | paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.get_screenshot_as_file('/Screenshots/foo.png') | | get_screenshot_as_png(self) -> bytes | Gets the screenshot of the current window as a binary data. | | :Usage: | :: | | driver.get_screenshot_as_png() | | get_window_position(self, windowHandle='current') -> dict | Gets the x,y position of the current window. | | :Usage: | :: | | driver.get_window_position() | | get_window_rect(self) -> dict | Gets the x, y coordinates of the window as well as height and width | of the current window. | | :Usage: | :: | | driver.get_window_rect() | | get_window_size(self, windowHandle: str = 'current') -> dict | Gets the width and height of the current window. | | :Usage: | :: | | driver.get_window_size() | | implicitly_wait(self, time_to_wait: float) -> None | Sets a sticky timeout to implicitly wait for an element to be found, | or a command to complete. This method only needs to be called one time | per session. To set the timeout for calls to execute_async_script, see | set_script_timeout. | | :Args: | - time_to_wait: Amount of time to wait (in seconds) | | :Usage: | :: | | driver.implicitly_wait(30) | | maximize_window(self) -> None | Maximizes the current window that webdriver is using. | | minimize_window(self) -> None | Invokes the window manager-specific 'minimize' operation. | | pin_script(self, script: str, script_key=None) -> selenium.webdriver.remote.script_key.ScriptKey | Store common javascript scripts to be executed later by a unique | hashable ID. | | print_page(self, print_options: Optional[selenium.webdriver.common.print_page_options.PrintOptions] = None) -> str | Takes PDF of the current page. | | The driver makes a best effort to return a PDF based on the | provided parameters. | | refresh(self) -> None | Refreshes the current page. | | :Usage: | :: | | driver.refresh() | | remove_all_credentials(self) -> None | Removes all credentials from the authenticator. | | remove_credential(self, credential_id: Union[str, bytearray]) -> None | Removes a credential from the authenticator. | | remove_virtual_authenticator(self) -> None | Removes a previously added virtual authenticator. | | The authenticator is no longer valid after removal, so no | methods may be called. | | save_screenshot(self, filename) -> bool | Saves a screenshot of the current window to a PNG image file. | Returns False if there is any IOError, else returns True. Use full | paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.save_screenshot('/Screenshots/foo.png') | | set_page_load_timeout(self, time_to_wait: float) -> None | Set the amount of time to wait for a page load to complete before | throwing an error. | | :Args: | - time_to_wait: The amount of time to wait | | :Usage: | :: | | driver.set_page_load_timeout(30) | | set_script_timeout(self, time_to_wait: float) -> None | Set the amount of time that the script should wait during an | execute_async_script call before throwing an error. | | :Args: | - time_to_wait: The amount of time to wait (in seconds) | | :Usage: | :: | | driver.set_script_timeout(30) | | set_user_verified(self, verified: bool) -> None | Sets whether the authenticator will simulate success or fail on user | verification. | | verified: True if the authenticator will pass user verification, False otherwise. | | set_window_position(self, x, y, windowHandle: str = 'current') -> dict | Sets the x,y position of the current window. (window.moveTo) | | :Args: | - x: the x-coordinate in pixels to set the window position | - y: the y-coordinate in pixels to set the window position | | :Usage: | :: | | driver.set_window_position(0,0) | | set_window_rect(self, x=None, y=None, width=None, height=None) -> dict | Sets the x, y coordinates of the window as well as height and width | of the current window. This method is only supported for W3C compatible | browsers; other browsers should use `set_window_position` and | `set_window_size`. | | :Usage: | :: | | driver.set_window_rect(x=10, y=10) | driver.set_window_rect(width=100, height=200) | driver.set_window_rect(x=10, y=10, width=100, height=200) | | set_window_size(self, width, height, windowHandle: str = 'current') -> None | Sets the width and height of the current window. (window.resizeTo) | | :Args: | - width: the width in pixels to set the window to | - height: the height in pixels to set the window to | | :Usage: | :: | | driver.set_window_size(800,600) | | start_client(self) | Called before starting a new session. | | This method may be overridden to define custom startup behavior. | | start_session(self, capabilities: dict) -> None | Creates a new session with the desired capabilities. | | :Args: | - capabilities - a capabilities dict to start the session with. | | stop_client(self) | Called after executing a quit command. | | This method may be overridden to define custom shutdown | behavior. | | unpin(self, script_key: selenium.webdriver.remote.script_key.ScriptKey) -> None | Remove a pinned script from storage. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.remote.webdriver.WebDriver: | | application_cache | Returns a ApplicationCache Object to interact with the browser app | cache. | | capabilities | Returns the drivers current capabilities being used. | | current_url | Gets the URL of the current page. | | :Usage: | :: | | driver.current_url | | current_window_handle | Returns the handle of the current window. | | :Usage: | :: | | driver.current_window_handle | | desired_capabilities | Returns the drivers current desired capabilities being used. | | log_types | Gets a list of the available log types. This only works with w3c | compliant browsers. | | :Usage: | :: | | driver.log_types | | mobile | | name | Returns the name of the underlying browser for this instance. | | :Usage: | :: | | name = driver.name | | page_source | Gets the source of the current page. | | :Usage: | :: | | driver.page_source | | switch_to | :Returns: | - SwitchTo: an object containing all options to switch focus into | | :Usage: | :: | | element = driver.switch_to.active_element | alert = driver.switch_to.alert | driver.switch_to.default_content() | driver.switch_to.frame('frame_name') | driver.switch_to.frame(1) | driver.switch_to.frame(driver.find_elements(By.TAG_NAME, "iframe")[0]) | driver.switch_to.parent_frame() | driver.switch_to.window('main') | | title | Returns the title of the current page. | | :Usage: | :: | | title = driver.title | | virtual_authenticator_id | Returns the id of the virtual authenticator. | | window_handles | Returns the handles of all windows within the current session. | | :Usage: | :: | | driver.window_handles | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.remote.webdriver.WebDriver: | | file_detector | | orientation | Gets the current orientation of the device. | | :Usage: | :: | | orientation = driver.orientation | | timeouts | Get all the timeouts that have been set on the current session. | | :Usage: | :: | | driver.timeouts | :rtype: Timeout | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.remote.webdriver.BaseWebDriver: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) WPEWebKitOptions = class Options(selenium.webdriver.common.options.ArgOptions) | WPEWebKitOptions() -> None | | Method resolution order: | Options | selenium.webdriver.common.options.ArgOptions | selenium.webdriver.common.options.BaseOptions | builtins.object | | Methods defined here: | | __init__(self) -> None | Initialize self. See help(type(self)) for accurate signature. | | to_capabilities(self) | Creates a capabilities with all the options that have been set and | returns a dictionary with everything. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | binary_location | Returns the location of the browser binary otherwise an empty | string. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | KEY = 'wpe:browserOptions' | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.options.ArgOptions: | | add_argument(self, argument) | Adds an argument to the list. | | :Args: | - Sets the arguments | | ignore_local_proxy_environment_variables(self) -> None | By calling this you will ignore HTTP_PROXY and HTTPS_PROXY from | being picked up and used. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.options.ArgOptions: | | arguments | :Returns: A list of arguments needed for the browser. | | default_capabilities | Return minimal capabilities necessary as a dictionary. | | ---------------------------------------------------------------------- | Data and other attributes inherited from selenium.webdriver.common.options.ArgOptions: | | BINARY_LOCATION_ERROR = 'Binary Location Must be a String' | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.options.BaseOptions: | | enable_mobile(self, android_package: Optional[str] = None, android_activity: Optional[str] = None, device_serial: Optional[str] = None) -> None | Enables mobile browser use for browsers that support it. | | :Args: | android_activity: The name of the android package to start | | set_capability(self, name, value) -> None | Sets a capability. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.options.BaseOptions: | | capabilities | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.common.options.BaseOptions: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | accept_insecure_certs | | browser_version | | enable_downloads | | page_load_strategy | | platform_name | | proxy | | set_window_rect | | strict_file_interactability | | timeouts | | unhandled_prompt_behavior WPEWebKitService = class Service(selenium.webdriver.common.service.Service) | WPEWebKitService(executable_path: str = 'WPEWebDriver', port: int = 0, log_path: Optional[str] = None, service_args: Optional[List[str]] = None, env: Optional[Mapping[str, str]] = None, **kwargs) | | A Service class that is responsible for the starting and stopping of | `WPEWebDriver`. | | :param executable_path: install path of the WPEWebDriver executable, defaults to `WPEWebDriver`. | :param port: Port for the service to run on, defaults to 0 where the operating system will decide. | :param service_args: (Optional) List of args to be passed to the subprocess when launching the executable. | :param log_path: (Optional) File path for the file to be opened and passed as the subprocess stdout/stderr handler. | :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. | | Method resolution order: | Service | selenium.webdriver.common.service.Service | abc.ABC | builtins.object | | Methods defined here: | | __init__(self, executable_path: str = 'WPEWebDriver', port: int = 0, log_path: Optional[str] = None, service_args: Optional[List[str]] = None, env: Optional[Mapping[str, str]] = None, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | command_line_args(self) -> List[str] | A List of program arguments (excluding the executable). | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.service.Service: | | __del__(self) -> None | | assert_process_still_running(self) -> None | Check if the underlying process is still running. | | is_connectable(self) -> bool | Establishes a socket connection to determine if the service running | on the port is accessible. | | send_remote_shutdown_command(self) -> None | Dispatch an HTTP request to the shutdown endpoint for the service in | an attempt to stop it. | | start(self) -> None | Starts the Service. | | :Exceptions: | - WebDriverException : Raised either when it can't start the service | or when it can't connect to the service | | stop(self) -> None | Stops the service. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.service.Service: | | service_url | Gets the url of the Service. | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.common.service.Service: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | path WebKitGTK = class WebDriver(selenium.webdriver.remote.webdriver.WebDriver) | WebKitGTK(executable_path='WebKitWebDriver', port=0, options=None, desired_capabilities=None, service_log_path=None, keep_alive=False) | | Controls the WebKitGTKDriver and allows you to drive the browser. | | Method resolution order: | WebDriver | selenium.webdriver.remote.webdriver.WebDriver | selenium.webdriver.remote.webdriver.BaseWebDriver | builtins.object | | Methods defined here: | | __init__(self, executable_path='WebKitWebDriver', port=0, options=None, desired_capabilities=None, service_log_path=None, keep_alive=False) | Creates a new instance of the WebKitGTK driver. | | Starts the service and then creates new instance of WebKitGTK Driver. | | :Args: | - executable_path : path to the executable. If the default is used it assumes the executable is in the $PATH. | - port : port you would like the service to run, if left as 0, a free port will be found. | - options : an instance of WebKitGTKOptions | - desired_capabilities : Dictionary object with desired capabilities | - service_log_path : Path to write service stdout and stderr output. | - keep_alive : Whether to configure RemoteConnection to use HTTP keep-alive. | | quit(self) | Closes the browser and shuts down the WebKitGTKDriver executable | that is started when starting the WebKitGTKDriver. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.remote.webdriver.WebDriver: | | __enter__(self) | | __exit__(self, exc_type: Optional[Type[BaseException]], exc: Optional[BaseException], traceback: Optional[traceback]) | | __repr__(self) | Return repr(self). | | add_cookie(self, cookie_dict) -> None | Adds a cookie to your current session. | | :Args: | - cookie_dict: A dictionary object, with required keys - "name" and "value"; | optional keys - "path", "domain", "secure", "httpOnly", "expiry", "sameSite" | | :Usage: | :: | | driver.add_cookie({'name' : 'foo', 'value' : 'bar'}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/'}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/', 'secure' : True}) | driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'sameSite' : 'Strict'}) | | add_credential(self, credential: selenium.webdriver.common.virtual_authenticator.Credential) -> None | Injects a credential into the authenticator. | | add_virtual_authenticator(self, options: selenium.webdriver.common.virtual_authenticator.VirtualAuthenticatorOptions) -> None | Adds a virtual authenticator with the given options. | | back(self) -> None | Goes one step backward in the browser history. | | :Usage: | :: | | driver.back() | | bidi_connection(self) | | close(self) -> None | Closes the current window. | | :Usage: | :: | | driver.close() | | create_web_element(self, element_id: str) -> selenium.webdriver.remote.webelement.WebElement | Creates a web element with the specified `element_id`. | | delete_all_cookies(self) -> None | Delete all cookies in the scope of the session. | | :Usage: | :: | | driver.delete_all_cookies() | | delete_cookie(self, name) -> None | Deletes a single cookie with the given name. | | :Usage: | :: | | driver.delete_cookie('my_cookie') | | delete_downloadable_files(self) -> None | Deletes all downloadable files. | | download_file(self, file_name: str, target_directory: str) -> None | Downloads a file with the specified file name to the target | directory. | | file_name: The name of the file to download. | target_directory: The path to the directory to save the downloaded file. | | execute(self, driver_command: str, params: dict = None) -> dict | Sends a command to be executed by a command.CommandExecutor. | | :Args: | - driver_command: The name of the command to execute as a string. | - params: A dictionary of named parameters to send with the command. | | :Returns: | The command's JSON response loaded into a dictionary object. | | execute_async_script(self, script: str, *args) | Asynchronously Executes JavaScript in the current window/frame. | | :Args: | - script: The JavaScript to execute. | - \*args: Any applicable arguments for your JavaScript. | | :Usage: | :: | | script = "var callback = arguments[arguments.length - 1]; " \ | "window.setTimeout(function(){ callback('timeout') }, 3000);" | driver.execute_async_script(script) | | execute_script(self, script, *args) | Synchronously Executes JavaScript in the current window/frame. | | :Args: | - script: The JavaScript to execute. | - \*args: Any applicable arguments for your JavaScript. | | :Usage: | :: | | driver.execute_script('return document.title;') | | file_detector_context(self, file_detector_class, *args, **kwargs) | Overrides the current file detector (if necessary) in limited | context. Ensures the original file detector is set afterwards. | | Example:: | | with webdriver.file_detector_context(UselessFileDetector): | someinput.send_keys('/etc/hosts') | | :Args: | - file_detector_class - Class of the desired file detector. If the class is different | from the current file_detector, then the class is instantiated with args and kwargs | and used as a file detector during the duration of the context manager. | - args - Optional arguments that get passed to the file detector class during | instantiation. | - kwargs - Keyword arguments, passed the same way as args. | | find_element(self, by='id', value: Optional[str] = None) -> selenium.webdriver.remote.webelement.WebElement | Find an element given a By strategy and locator. | | :Usage: | :: | | element = driver.find_element(By.ID, 'foo') | | :rtype: WebElement | | find_elements(self, by='id', value: Optional[str] = None) -> List[selenium.webdriver.remote.webelement.WebElement] | Find elements given a By strategy and locator. | | :Usage: | :: | | elements = driver.find_elements(By.CLASS_NAME, 'foo') | | :rtype: list of WebElement | | forward(self) -> None | Goes one step forward in the browser history. | | :Usage: | :: | | driver.forward() | | fullscreen_window(self) -> None | Invokes the window manager-specific 'full screen' operation. | | get(self, url: str) -> None | Loads a web page in the current browser session. | | get_cookie(self, name) -> Optional[Dict] | Get a single cookie by name. Returns the cookie if found, None if | not. | | :Usage: | :: | | driver.get_cookie('my_cookie') | | get_cookies(self) -> List[dict] | Returns a set of dictionaries, corresponding to cookies visible in | the current session. | | :Usage: | :: | | driver.get_cookies() | | get_credentials(self) -> List[selenium.webdriver.common.virtual_authenticator.Credential] | Returns the list of credentials owned by the authenticator. | | get_downloadable_files(self) -> dict | Retrieves the downloadable files as a map of file names and their | corresponding URLs. | | get_log(self, log_type) | Gets the log for a given log type. | | :Args: | - log_type: type of log that which will be returned | | :Usage: | :: | | driver.get_log('browser') | driver.get_log('driver') | driver.get_log('client') | driver.get_log('server') | | get_pinned_scripts(self) -> List[str] | | get_screenshot_as_base64(self) -> str | Gets the screenshot of the current window as a base64 encoded string | which is useful in embedded images in HTML. | | :Usage: | :: | | driver.get_screenshot_as_base64() | | get_screenshot_as_file(self, filename) -> bool | Saves a screenshot of the current window to a PNG image file. | Returns False if there is any IOError, else returns True. Use full | paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.get_screenshot_as_file('/Screenshots/foo.png') | | get_screenshot_as_png(self) -> bytes | Gets the screenshot of the current window as a binary data. | | :Usage: | :: | | driver.get_screenshot_as_png() | | get_window_position(self, windowHandle='current') -> dict | Gets the x,y position of the current window. | | :Usage: | :: | | driver.get_window_position() | | get_window_rect(self) -> dict | Gets the x, y coordinates of the window as well as height and width | of the current window. | | :Usage: | :: | | driver.get_window_rect() | | get_window_size(self, windowHandle: str = 'current') -> dict | Gets the width and height of the current window. | | :Usage: | :: | | driver.get_window_size() | | implicitly_wait(self, time_to_wait: float) -> None | Sets a sticky timeout to implicitly wait for an element to be found, | or a command to complete. This method only needs to be called one time | per session. To set the timeout for calls to execute_async_script, see | set_script_timeout. | | :Args: | - time_to_wait: Amount of time to wait (in seconds) | | :Usage: | :: | | driver.implicitly_wait(30) | | maximize_window(self) -> None | Maximizes the current window that webdriver is using. | | minimize_window(self) -> None | Invokes the window manager-specific 'minimize' operation. | | pin_script(self, script: str, script_key=None) -> selenium.webdriver.remote.script_key.ScriptKey | Store common javascript scripts to be executed later by a unique | hashable ID. | | print_page(self, print_options: Optional[selenium.webdriver.common.print_page_options.PrintOptions] = None) -> str | Takes PDF of the current page. | | The driver makes a best effort to return a PDF based on the | provided parameters. | | refresh(self) -> None | Refreshes the current page. | | :Usage: | :: | | driver.refresh() | | remove_all_credentials(self) -> None | Removes all credentials from the authenticator. | | remove_credential(self, credential_id: Union[str, bytearray]) -> None | Removes a credential from the authenticator. | | remove_virtual_authenticator(self) -> None | Removes a previously added virtual authenticator. | | The authenticator is no longer valid after removal, so no | methods may be called. | | save_screenshot(self, filename) -> bool | Saves a screenshot of the current window to a PNG image file. | Returns False if there is any IOError, else returns True. Use full | paths in your filename. | | :Args: | - filename: The full path you wish to save your screenshot to. This | should end with a `.png` extension. | | :Usage: | :: | | driver.save_screenshot('/Screenshots/foo.png') | | set_page_load_timeout(self, time_to_wait: float) -> None | Set the amount of time to wait for a page load to complete before | throwing an error. | | :Args: | - time_to_wait: The amount of time to wait | | :Usage: | :: | | driver.set_page_load_timeout(30) | | set_script_timeout(self, time_to_wait: float) -> None | Set the amount of time that the script should wait during an | execute_async_script call before throwing an error. | | :Args: | - time_to_wait: The amount of time to wait (in seconds) | | :Usage: | :: | | driver.set_script_timeout(30) | | set_user_verified(self, verified: bool) -> None | Sets whether the authenticator will simulate success or fail on user | verification. | | verified: True if the authenticator will pass user verification, False otherwise. | | set_window_position(self, x, y, windowHandle: str = 'current') -> dict | Sets the x,y position of the current window. (window.moveTo) | | :Args: | - x: the x-coordinate in pixels to set the window position | - y: the y-coordinate in pixels to set the window position | | :Usage: | :: | | driver.set_window_position(0,0) | | set_window_rect(self, x=None, y=None, width=None, height=None) -> dict | Sets the x, y coordinates of the window as well as height and width | of the current window. This method is only supported for W3C compatible | browsers; other browsers should use `set_window_position` and | `set_window_size`. | | :Usage: | :: | | driver.set_window_rect(x=10, y=10) | driver.set_window_rect(width=100, height=200) | driver.set_window_rect(x=10, y=10, width=100, height=200) | | set_window_size(self, width, height, windowHandle: str = 'current') -> None | Sets the width and height of the current window. (window.resizeTo) | | :Args: | - width: the width in pixels to set the window to | - height: the height in pixels to set the window to | | :Usage: | :: | | driver.set_window_size(800,600) | | start_client(self) | Called before starting a new session. | | This method may be overridden to define custom startup behavior. | | start_session(self, capabilities: dict) -> None | Creates a new session with the desired capabilities. | | :Args: | - capabilities - a capabilities dict to start the session with. | | stop_client(self) | Called after executing a quit command. | | This method may be overridden to define custom shutdown | behavior. | | unpin(self, script_key: selenium.webdriver.remote.script_key.ScriptKey) -> None | Remove a pinned script from storage. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.remote.webdriver.WebDriver: | | application_cache | Returns a ApplicationCache Object to interact with the browser app | cache. | | capabilities | Returns the drivers current capabilities being used. | | current_url | Gets the URL of the current page. | | :Usage: | :: | | driver.current_url | | current_window_handle | Returns the handle of the current window. | | :Usage: | :: | | driver.current_window_handle | | desired_capabilities | Returns the drivers current desired capabilities being used. | | log_types | Gets a list of the available log types. This only works with w3c | compliant browsers. | | :Usage: | :: | | driver.log_types | | mobile | | name | Returns the name of the underlying browser for this instance. | | :Usage: | :: | | name = driver.name | | page_source | Gets the source of the current page. | | :Usage: | :: | | driver.page_source | | switch_to | :Returns: | - SwitchTo: an object containing all options to switch focus into | | :Usage: | :: | | element = driver.switch_to.active_element | alert = driver.switch_to.alert | driver.switch_to.default_content() | driver.switch_to.frame('frame_name') | driver.switch_to.frame(1) | driver.switch_to.frame(driver.find_elements(By.TAG_NAME, "iframe")[0]) | driver.switch_to.parent_frame() | driver.switch_to.window('main') | | title | Returns the title of the current page. | | :Usage: | :: | | title = driver.title | | virtual_authenticator_id | Returns the id of the virtual authenticator. | | window_handles | Returns the handles of all windows within the current session. | | :Usage: | :: | | driver.window_handles | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.remote.webdriver.WebDriver: | | file_detector | | orientation | Gets the current orientation of the device. | | :Usage: | :: | | orientation = driver.orientation | | timeouts | Get all the timeouts that have been set on the current session. | | :Usage: | :: | | driver.timeouts | :rtype: Timeout | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.remote.webdriver.BaseWebDriver: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) WebKitGTKOptions = class Options(selenium.webdriver.common.options.ArgOptions) | WebKitGTKOptions() -> None | | Method resolution order: | Options | selenium.webdriver.common.options.ArgOptions | selenium.webdriver.common.options.BaseOptions | builtins.object | | Methods defined here: | | __init__(self) -> None | Initialize self. See help(type(self)) for accurate signature. | | to_capabilities(self) | Creates a capabilities with all the options that have been set and | returns a dictionary with everything. | | ---------------------------------------------------------------------- | Readonly properties defined here: | | default_capabilities | Return minimal capabilities necessary as a dictionary. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | binary_location | :Returns: The location of the browser binary otherwise an empty | string. | | overlay_scrollbars_enabled | :Returns: Whether overlay scrollbars should be enabled. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | KEY = 'webkitgtk:browserOptions' | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.options.ArgOptions: | | add_argument(self, argument) | Adds an argument to the list. | | :Args: | - Sets the arguments | | ignore_local_proxy_environment_variables(self) -> None | By calling this you will ignore HTTP_PROXY and HTTPS_PROXY from | being picked up and used. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.options.ArgOptions: | | arguments | :Returns: A list of arguments needed for the browser. | | ---------------------------------------------------------------------- | Data and other attributes inherited from selenium.webdriver.common.options.ArgOptions: | | BINARY_LOCATION_ERROR = 'Binary Location Must be a String' | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.options.BaseOptions: | | enable_mobile(self, android_package: Optional[str] = None, android_activity: Optional[str] = None, device_serial: Optional[str] = None) -> None | Enables mobile browser use for browsers that support it. | | :Args: | android_activity: The name of the android package to start | | set_capability(self, name, value) -> None | Sets a capability. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.options.BaseOptions: | | capabilities | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.common.options.BaseOptions: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | accept_insecure_certs | | browser_version | | enable_downloads | | page_load_strategy | | platform_name | | proxy | | set_window_rect | | strict_file_interactability | | timeouts | | unhandled_prompt_behavior WebKitGTKService = class Service(selenium.webdriver.common.service.Service) | WebKitGTKService(executable_path: str = 'WebKitWebDriver', port: int = 0, log_path: Optional[str] = None, service_args: Optional[List[str]] = None, env: Optional[Mapping[str, str]] = None, **kwargs) | | A Service class that is responsible for the starting and stopping of | `WPEWebDriver`. | | :param executable_path: install path of the WebKitWebDriver executable, defaults to `WebKitWebDriver`. | :param port: Port for the service to run on, defaults to 0 where the operating system will decide. | :param service_args: (Optional) List of args to be passed to the subprocess when launching the executable. | :param log_path: (Optional) File path for the file to be opened and passed as the subprocess stdout/stderr handler. | :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. | | Method resolution order: | Service | selenium.webdriver.common.service.Service | abc.ABC | builtins.object | | Methods defined here: | | __init__(self, executable_path: str = 'WebKitWebDriver', port: int = 0, log_path: Optional[str] = None, service_args: Optional[List[str]] = None, env: Optional[Mapping[str, str]] = None, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | command_line_args(self) -> List[str] | A List of program arguments (excluding the executable). | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Methods inherited from selenium.webdriver.common.service.Service: | | __del__(self) -> None | | assert_process_still_running(self) -> None | Check if the underlying process is still running. | | is_connectable(self) -> bool | Establishes a socket connection to determine if the service running | on the port is accessible. | | send_remote_shutdown_command(self) -> None | Dispatch an HTTP request to the shutdown endpoint for the service in | an attempt to stop it. | | start(self) -> None | Starts the Service. | | :Exceptions: | - WebDriverException : Raised either when it can't start the service | or when it can't connect to the service | | stop(self) -> None | Stops the service. | | ---------------------------------------------------------------------- | Readonly properties inherited from selenium.webdriver.common.service.Service: | | service_url | Gets the url of the Service. | | ---------------------------------------------------------------------- | Data descriptors inherited from selenium.webdriver.common.service.Service: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | path DATA __all__ = ['Firefox', 'FirefoxProfile', 'FirefoxOptions', 'FirefoxServ... VERSION 4.15.2 FILE /opt/anaconda3/lib/python3.9/site-packages/selenium/webdriver/__init__.py
http://chromedriver.storage.googleapis.com/index.html
Anaconda的bin文件夹
下#from selenium import webdriver
#browser = webdriver.Chrome(executable_path = '/opt/anaconda3/bin/chromedriver')
from selenium import webdriver
# webdriver.Chrome?
browser = webdriver.Chrome()#executable_path = '/opt/anaconda3/bin/chromedriver')
browser.get("http://music.163.com")
#print(browser.page_source)
print('i am fine!')
browser.close()
i am fine!
单个元素查找
这里我们通过三种不同的方式去获取响应的元素,第一种是通过id的方式,第二个是CSS选择器,第三种是xpath选择器,结果都是相同的。
from selenium.webdriver.common.by import By
# from selenium import webdriver
browser = webdriver.Chrome()
browser.get("http://music.163.com")
# <input type="text" name="srch" id="srch" class="txt j-flag" value="" style="opacity: 1;">
input_first = browser.find_element(By.ID, "srch")
#srch
input_second = browser.find_element(By.CSS_SELECTOR, "#srch")
# //*[@id="srch"]
input_third = browser.find_element(By.XPATH, '//*[@id="srch"]')
print(input_first)
print(input_second)
print(input_third)
browser.close()
<selenium.webdriver.remote.webelement.WebElement (session="6044e39ce7837116564c017e26168d0d", element="890B8BD1FA16A3DFDB1E648079C765A2_element_110")> <selenium.webdriver.remote.webelement.WebElement (session="6044e39ce7837116564c017e26168d0d", element="890B8BD1FA16A3DFDB1E648079C765A2_element_110")> <selenium.webdriver.remote.webelement.WebElement (session="6044e39ce7837116564c017e26168d0d", element="890B8BD1FA16A3DFDB1E648079C765A2_element_110")>
# 下面这种方式是比较通用的一种方式:这里需要记住By模块所以需要导入
from selenium.webdriver.common.by import By
browser = webdriver.Chrome()
browser.get("http://music.163.com")
#<input type="text" name="srch" id="srch" class="txt j-flag" value="" style="opacity: 1;">
input_first = browser.find_element(By.ID,"srch")
print(input_first)
browser.close()
<selenium.webdriver.remote.webelement.WebElement (session="e3a669935a63ce535140fbca9860413a", element="0cbf3c21-adf9-4704-aa61-396dadad994b")>
其实多个元素和单个元素的区别,举个例子:find_elements,单个元素是find_element,其他使用上没什么区别,通过其中的一个例子演示:
browser = webdriver.Chrome()
browser.get("http://music.163.com")
lis = browser.find_elements(By.CSS_SELECTOR, 'body')
print(lis)
browser.close()
[<selenium.webdriver.remote.webelement.WebElement (session="43a06e7cb48e9c5f2497892a32d01c84", element="74B75E1306D9F68C640E243C7EB3E973_element_111")>]
当然上面的方式也是可以通过导入from selenium.webdriver.common.by import By
这种方式实现
lis = browser.find_elements(By.CSS_SELECTOR,'.service-bd li')
同样的在单个元素中查找的方法在多个元素查找中同样存在:
对于获取的元素调用交互方法
import time
browser = webdriver.Chrome()
browser.get("https://music.163.com/")
input_str = browser.find_element(By.ID, 'srch')
input_str.send_keys("周杰伦")
time.sleep(3) #休眠,模仿人工搜索
#input_str.clear()
#input_str.send_keys("林俊杰")
#time.sleep(3)
browser.close()
运行的结果可以看出程序会自动打开Chrome浏览器并打开淘宝输入ipad,然后删除,重新输入MacBook pro,并点击搜索
Selenium所有的api文档:http://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.common.action_chains
这是一个非常有用的方法,这里就可以直接调用js方法来实现一些操作, 下面的例子是通过登录知乎然后通过js翻到页面底部,并弹框提示
from selenium import webdriver
browser = webdriver.Chrome()
browser.get("http://www.cppcc.gov.cn/")
browser.execute_script('window.scrollTo(0, document.body.scrollHeight)')
#browser.execute_script('alert("To Bottom")')
time.sleep(3)
browser.close()
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("disable-infobars")
options.add_argument('--profile-directory=Default')
options.add_argument("--disable-extensions")
options.add_argument('incognito')
options.add_argument('disable-geolocation')
options.add_argument('ignore-certificate-errors')
options.add_argument('disable-popup-blocking')
options.add_argument('disable-web-security')
options.add_argument('--disable-infobars')
options.add_argument('disable-translate')
browser = webdriver.Chrome(options=options, executable_path = '/opt/anaconda3/bin/chromedriver')
browser.get("https://github.com")
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("disable-infobars")
options.add_argument('--profile-directory=Default')
#options.add_argument("--user-data-dir=~/Library/Application\ Support/Google/Chrome/Default/")
browser = webdriver.Chrome(options=options, executable_path=r"chromedriver")
browser.get('https://mail.google.com/mail/u/0/')
!pip3 install pyppeteer
Requirement already satisfied: pyppeteer in /usr/local/lib/python3.7/site-packages (0.0.25) Requirement already satisfied: websockets in /usr/local/lib/python3.7/site-packages (from pyppeteer) (8.1) Requirement already satisfied: tqdm in /usr/local/lib/python3.7/site-packages (from pyppeteer) (4.43.0) Requirement already satisfied: pyee in /usr/local/lib/python3.7/site-packages (from pyppeteer) (7.0.1) Requirement already satisfied: urllib3 in /usr/local/lib/python3.7/site-packages (from pyppeteer) (1.25.8) Requirement already satisfied: appdirs in /usr/local/lib/python3.7/site-packages (from pyppeteer) (1.4.3)
import nest_asyncio
nest_asyncio.apply()
import asyncio
from pyppeteer import launch
width, height = 1366, 768
async def main():
browser = await launch(headless=False,
args=[f'--window-size={width},{height}'])
page = await browser.newPage()
await page.setViewport({'width': width, 'height': height})
await page.goto('https://www.taobao.com')
await asyncio.sleep(100)
asyncio.get_event_loop().run_until_complete(main())
import asyncio
from pyppeteer import launch
async def main():
browser = await launch(headless=False, args=['--disable-infobars'])
page = await browser.newPage()
await page.goto('https://login.taobao.com/member/login.jhtml?redirectURL=https://www.taobao.com/')
await page.evaluate(
'''() =>{ Object.defineProperties(navigator,{ webdriver:{ get: () => false } }) }''')
await asyncio.sleep(100)
asyncio.get_event_loop().run_until_complete(main())
from selenium import webdriver
browser = webdriver.Chrome()
browser.get("https://www.privco.com/home/login") #需要翻墙打开网址
username = 'fake_username'
password = 'fake_password'
browser.find_element_by_id("username").clear()
browser.find_element_by_id("username").send_keys(username)
browser.find_element_by_id("password").clear()
browser.find_element_by_id("password").send_keys(password)
browser.find_element_by_css_selector("#login-form > div:nth-child(5) > div > button").click()
# url = "https://www.privco.com/private-company/329463"
def download_excel(url):
browser.get(url)
name = url.split('/')[-1]
title = browser.title
source = browser.page_source
with open(name+'.html', 'w') as f:
f.write(source)
try:
soup = BeautifulSoup(source, 'html.parser')
url_new = soup.find('span', {'class', 'profile-name'}).a['href']
url_excel = url_new + '/export'
browser.get(url_excel)
except Exception as e:
print(url, 'no excel')
pass
urls = [ 'https://www.privco.com/private-company/1135789',
'https://www.privco.com/private-company/542756',
'https://www.privco.com/private-company/137908',
'https://www.privco.com/private-company/137138']
for k, url in enumerate(urls):
print(k)
try:
download_excel(url)
except Exception as e:
print(url, e)
0 https://www.privco.com/private-company/1135789 no excel 1 https://www.privco.com/private-company/542756 no excel 2 https://www.privco.com/private-company/137908 no excel 3 https://www.privco.com/private-company/137138 no excel