webdriver.Chrome
- class selenium_driverless.webdriver.Chrome(options=None, timeout=30, debug=False, max_ws_size=134217728)[source]
Control the chromium based browsers without any driver.
- __init__(options=None, timeout=30, debug=False, max_ws_size=134217728)[source]
Creates a new instance of the chrome target. Starts the service and then creates new instance of chrome target.
options = webdriver.ChromeOptions.rst() async with webdriver.Chrome(options=options) as driver: await driver.get('https://abrahamjuliot.github.io/creepjs/', wait_load=True) print(await driver.title)
- Parameters:
options (
Optional
[Options
]) – this takes an instance of ChromeOptions.rsttimeout (
float
) – timeout in seconds to start chromedebug (
bool
) – redirect errors from the chromium process output (stderr) to consolemax_ws_size (
int
) – maximum size for websocket messages in bytes. 2^27 ~= 130 MB by default
- async add_cookie(cookie_dict)[source]
Adds a cookie in the current (incognito-) context
- Parameters:
cookie_dict (
dict
) – see Network.CookieParam- Return type:
None
- async back()[source]
Goes one step backward in the browser history on the current target (has to be a tab).
- Return type:
None
- property base_context: Context
the Context which isn’t incognito
- property base_target: BaseTarget
The connection handle for the global connection to Chrome
Warning
only the bindings for using the CDP-protocol on BaseTarget supported
- async close(timeout=2)[source]
Closes the current target (only works for tabs). :type timeout:
float
:param timeout: timeout in seconds for the tab to close- Return type:
None
- property contexts: Dict[str, Context]
async all (incognito) contexts on Chrome.
- property current_context: Context
the current context switched to
- property current_pointer: Pointer
async the Pointer of the current Target
- property current_target: Target
the current Target
- property current_target_info: TargetInfo
async TargetInfo of the current target
- property current_url: str
async current URL of the current Target
- property current_window_handle: str
current TargetId
Warning
this is deprecated and will be removed use
webdriver.Chrome.current_target.id
instead
- property current_window_id
async the
WindowId
of the window the current Target belongs to
- async delete_all_cookies()[source]
Delete all cookies in the current (incognito-) context.
- Return type:
None
- async delete_cookie(name, url=None, domain=None, path=None)[source]
Deletes a single cookie with the given name in the current tab.
- Parameters:
name (
str
) – name of the cookie to deleteurl (
Optional
[str
]) – url of the cookiedomain (
Optional
[str
]) – domain of the cookiepath (
Optional
[str
]) – path of the cookie
- Return type:
None
- async ensure_extensions_incognito_allowed()[source]
ensure that all installed Chrome-extensions are allowed in incognito context.
Warning
Generally, the extension decides whether to use the
split
,spanning
ornot_allowed
configuration. For changing this behaviour, you’ll have to modify themanifest.json
file within the compressed extension or directory. See developer.chrome.com/docs/extensions/reference/manifest/incognito.
- async execute_async_script(script, *args, max_depth=2, serialization=None, timeout=2, target_id=None, execution_context_id=None, unique_context=False)[source]
executes JavaScript asynchronously on
GlobalThis
such asresolve = arguments[arguments.length-1]
this
refers toglobalThis
(=> window)see
Chrome.execute_raw_script
for argument descriptions
- async execute_raw_script(script, *args, await_res=False, serialization='deep', max_depth=None, timeout=2, execution_context_id=None, unique_context=False)[source]
executes a JavaScript on
GlobalThis
such asfunction(...arguments){return document}
this
refers toglobalThis
(=> window)- Parameters:
script (
str
) – the script as a stringargs – the argument which are passed to the function. Those can be either json-serializable or a RemoteObject such as WebELement
await_res (
bool
) – whether to await the function or the return value of itserialization (
Union
[Literal
['deep'
],Literal
['json'
],Literal
['idOnly'
]]) – can be one ofdeep
,json
,idOnly
max_depth (
Optional
[int
]) – The maximum depth objects get serialized.timeout (
int
) – the maximum time to wait for the execution to completeexecution_context_id (
Optional
[str
]) – the execution context id to run the JavaScript in. Exclusive with unique_contextunique_context (
bool
) – whether to use a isolated context to run the Script in.
- async execute_script(script, *args, max_depth=2, serialization=None, timeout=None, target_id=None, execution_context_id=None, unique_context=False)[source]
executes JavaScript synchronously on
GlobalThis
such asreturn document
this
refers toglobalThis
(=> window)see
Chrome.execute_raw_script
for argument descriptions
- async forward()[source]
Goes one step forward in the browser history on the current target (has to be a tab).
- Return type:
None
- property frame_tree: dict
async all nested frames within the current target
- async fullscreen_window()[source]
enters fullscreen on the window the current Target belongs to
- Return type:
None
- async get(url, referrer=None, wait_load=True, timeout=30)[source]
Loads a web page in the current Target
- Parameters:
url (
str
) – the url to load.referrer (
Optional
[str
]) – the referrer to load the page withwait_load (
bool
) – whether to wait for the webpage to loadtimeout (
float
) – the maximum time in seconds for waiting on load
- Return type:
None
Warning
loading pages which initiate a download requires to set
wait_load=False
for now. see issues#140
- async get_cookie(name)[source]
Get a single cookie by name. Returns the cookie if found, None if not.
- Parameters:
name – name of the cookie
- Return type:
Optional
[Dict
]
- async get_target(target_id=None, timeout=2)[source]
get a Target by TargetId for advanced usage of the CDP protocol :type target_id:
Optional
[str
] :param target_id: :type timeout:float
:param timeout: timeout in seconds for connecting to the target if it’s not tracked already- Return type:
Target
- async get_target_for_iframe(iframe)[source]
get the Target for a specific iframe
Warning
only cross-iframes have a Target due to OOPIF. See site-isolation For a general solution, have a look at
WebElement.content_document
instead- Parameters:
iframe (
WebElement
) – the iframe to get the Target for- Return type:
Target
- async get_targets(_type=None, context_id='self')[source]
get all targets within the current context :type _type:
Union
[Literal
['page'
],Literal
['background_page'
],Literal
['service_worker'
],Literal
['browser'
],Literal
['other'
],None
] :param _type: filter by target type :type context_id:str
:param context_id: ifNone
, this function returns all targets for all contexts.- Return type:
Dict
[str
,TargetInfo
]
- async get_targets_for_iframes(iframes)[source]
returns a list of targets for iframes see
webdriver.Chrome.get_target_for_iframe
for more information- Parameters:
iframes (
List
[WebElement
]) – the iframe to get the targets for- Return type:
List
[Target
]
- async maximize_window()[source]
Maximizes the window the current Target belongs to
- Return type:
None
- async minimize_window()[source]
minimizes the window the current Target belongs to. :rtype:
None
Warning
Minimizing isn’t recommended as it can throttle some functionalities in chrome.
- property mv3_extension: Target
async the target for the background script of the by default loaded Chrome-extension (manifest-version==3)
- async new_context(proxy_bypass_list=None, proxy_server=True, universal_access_origins=None, url='about:blank')[source]
creates a new (incognito) context
- Parameters:
url (
str
) – the url the first tab will start at. “about:blank” by defaultuniversal_access_origins (
Optional
[List
[str
]]) – An optional list of origins to grant unlimited cross-origin access to. Parts of the URL other than those constituting origin are ignored
- Return type:
Context
Warning
The proxy parameter doesn’t work on Windows due to crbug#1310057.
- Parameters:
proxy_server (
str
) – a proxy-server to use for the contextproxy_bypass_list (
Optional
[List
[str
]]) – a list of proxies to ignore
- async new_window(type_hint='tab', url='', activate=True)[source]
Creates a new window or tab in the current context
- Parameters:
type_hint (
Union
[Literal
['tab'
],Literal
['window'
]]) – whether to create a tab or windowurl – the url which the new window should start on. Defaults to about:blank
activate (
bool
) – whether to explicitly activate/focus the window
- Return type:
Target
new_target = driver.new_window('tab')
- async normalize_window()[source]
Normalizes the window position and size on the window the current Target belongs to
- property page_source: str
async html of the current page.
- async quit(timeout=30, clean_dirs=True)[source]
Closes Chrome :type timeout:
float
:param timeout: the maximum time waiting for chrome to quit correctly :type clean_dirs:bool
:param clean_dirs: whether to clean out the user-data-dir directory- Return type:
None
- async set_window_state(state)[source]
sets the window state on the window the current Target belongs to :type state:
Union
[Literal
['normal'
],Literal
['minimized'
],Literal
['maximized'
],Literal
['fullscreen'
]] :param state: the state to set
- async static sleep(time_to_wait)[source]
Note
use this one instead of time.sleep in the sync version.
- Parameters:
time_to_wait – time in seconds to sleep
- Return type:
None
- property targets: Dict[str, TargetInfo]
async all targets within the current context
- property title: str
async the title of the current target
- property window_handles: List[TargetInfo]
async TargetInfo on all tabs in the current context
Warning
the tabs aren’t ordered by position in the window. Do not rely on the index, but iterate and filter them.