
     f                     |   d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z& ddl'm(Z( ddl'm)Z) ddl'm*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4 dd l3m5Z5 dd!l6m7Z7 dd"l8m9Z9 dd#l:m;Z; dd$l<m=Z= dd%l>m?Z? dd&l@mAZA dd'lBmCZC daDdaEd( ZFd) ZGd4d+ZHd,ee"         d-efd.ZI G d/ d0e1          ZJ G d2 d3eJ          ZKdS )5zThe WebDriver implementation.    N)ABCMeta)	b64decode)urlsafe_b64encode)asynccontextmanager)contextmanager)import_module)Dict)List)Optional)Union)InvalidArgumentException)JavascriptException)NoSuchCookieException)NoSuchElementException)WebDriverException)Script)By)BaseOptions)PrintOptions)Timeouts)
Credential)VirtualAuthenticatorOptions)required_virtual_authenticator)
RelativeBy   )BidiConnection)Command)ErrorHandler)FileDetector)LocalFileDetector)Mobile)RemoteConnection)	ScriptKey)
ShadowRoot)SwitchTo)
WebElement)WebSocketConnectionc                  6    t           st          d          a d S d S )Nz"selenium.webdriver.common.bidi.cdp)cdpr        f/var/www/api.educacionweb.es/myenv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py
import_cdpr-   I   s)     B@AAB Br+   c                 |    t          j        |           } i }|                                 D ]
\  }}|||<   di g|diS )a  Makes a W3C alwaysMatch capabilities object.

    Filters out capability names that are not in the W3C spec. Spec-compliant
    drivers will reject requests containing unknown capability names.

    Moves the Firefox profile, if present, from the old location to the new Firefox
    options object.

    :Args:
     - caps - A dictionary of capabilities requested by the caller.
    capabilities)
firstMatchalwaysMatch)copydeepcopyitems)capsalways_matchkvs       r,   _create_capsr9   O   sS     =DL

  1QB4MMNNr+   Fc                      ddl m} ddlm} ddlm} ddlm} ||||g}t           fd|D             t                    }	 |	|||          S )Nr   )ChromeRemoteConnection)EdgeRemoteConnection)FirefoxRemoteConnection)SafariRemoteConnectionc              3   X   K   | ]$}|j                             d           k     |V  %dS )browserNameN)browser_nameget).0cr/   s     r,   	<genexpr>z(get_remote_connection.<locals>.<genexpr>i   s>      __!Q^|?O?OP]?^?^-^-^A-^-^-^-^__r+   )
keep_aliveignore_proxy)
+selenium.webdriver.chrome.remote_connectionr;   )selenium.webdriver.edge.remote_connectionr<   ,selenium.webdriver.firefox.remote_connectionr=   +selenium.webdriver.safari.remote_connectionr>   nextr"   )
r/   command_executorrF   ignore_local_proxyr;   r<   r=   r>   
candidateshandlers
   `         r,   get_remote_connectionrQ   b   s    RRRRRRNNNNNNTTTTTTRRRRRR(*>@VXopJ____z___aqrrG7#
I[\\\\r+   optionsreturnc                 R   di i}g }| D ])}|                     |                                           *t          |          }i }t          |          D ]}|}|dz   |k     r||                                         }|D ]e}	|	||dz                                            v rD||         |	         ||dz            |	         k    r#|                    |	||         |	         i           fi }
|                                D ]
\  }}||
|<   |D ]
}|
D ]}||= |
|d         d<   ||d         d<   |S )Nr/   r   r1   r0   )appendto_capabilitieslenrangekeysupdater4   )rR   r/   optsopt	opts_sizesamesiesi	min_index
first_keyskysalwaysr7   r8   s                r,   create_matchesrd   n   s   "B'LD + +C''))****D		IH 9 E E	q59i--//J! E E$q1u+**,,,,Is+tAE{3/??? d9oc.B(CDDDF    1q		   	 	A!	 39L /15L .r+   c                       e Zd ZdZdS )BaseWebDriverzAbstract Base Class for all Webdriver subtypes.

    ABC's allow custom implementations of Webdriver to be registered so
    that isinstance type checks will succeed.
    N)__name__
__module____qualname____doc__r*   r+   r,   rf   rf      s           r+   rf   )	metaclassc                      e Zd ZdZeZeZ	 	 	 	 dqdee	e
f         dedee         deeeee         f                  d	df
d
Zd Zd Zdej        ej        e                  dej        e         dej        ej                 fdZed             Zed	efd            Zed	e	fd            Zd Zd Z de!d	dfdZ"d Z#de	d	efdZ$d Z%drde	de!d	e!fdZ&de	d	dfd Z'ed	e	fd!            Z(drd"e	d	e)fd#Z*d$e)d	dfd%Z+d	ee	         fd&Z,d' Z-d"e	fd(Z.ed	e	fd)            Z/ed	e	fd*            Z0dsd+Z1dsd,Z2ed	e	fd-            Z3ed	ee	         fd.            Z4dsd/Z5dsd0Z6dsd1Z7drd2ee8         d	e	fd3Z9ed	e:fd4            Z;dsd5Z<dsd6Z=dsd7Z>d	ee!         fd8Z?d	ej        ej@                 fd9ZAdsd:ZBdsd;ZCdsd<ZDd=eEd	dfd>ZFd=eEd	dfd?ZGd=eEd	dfd@ZHed	eIfdA            ZJeJjK        dsdB            ZJeLjM        dfdCee	         d	efdDZNeLjM        dfdCee	         d	ee         fdEZOed	e!fdF            ZPd	efdGZQd	efdHZRd	eSfdIZTd	e	fdJZUdtdLe	d	dfdMZVdtdLe	d	e!fdNZWdtdOeEdPeEdLe	d	e!fdQZXdtd	e!fdRZYdLe	d	dfdSZZd	e!fdTZ[dud	e!fdUZ\ed	efdV            Z]e]jK        dsdW            Z]edX             Z^e^jK        dsdY            Z^edZ             Z_d[ Z`d\ Zaebd]             Zced^             Zdd_ Zed` Zfdegd	dfdaZhed	e	fdb            Ziejdsdc            Zkejddeld	dfde            Zmejd	eel         fdf            Znejdgee	eof         d	dfdh            Zpejdsdi            Zqejdjed	dfdk            Zrd	e!fdlZsdme	dne	d	dfdoZtdsdpZudS )v	WebDrivera  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.
    http://127.0.0.1:4444TNrM   rF   file_detectorrR   rS   c                 ^   t          |t                    rt          |          }d}n|                                }|j        }|| _        t          | j        t          t          f          rt          ||||          | _        d| _	        d| _
        i | _        i | _        t                      | _        t          |           | _        t#          |           | _        |pt'                      | _        d| _        |                                  |                     |           d| _        d| _        dS )a  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
        F)rM   rF   rN   TN)
isinstancelistrd   rV   _ignore_local_proxyrM   strbytesrQ   
_is_remote
session_idr5   pinned_scriptsr   error_handlerr%   
_switch_tor!   _mobiler    ro   _authenticator_idstart_clientstart_session_websocket_connection_script)selfrM   rF   ro   rR   r/   rs   s          r,   __init__zWebDriver.__init__   s$   ( gt$$ 	>)'22L"'"2244L")"= 0d+c5\:: 	$9!1%#6	% % %D! 	 )^^"4..d||*A.?.A.A!%<(((%)"r+   c                 l    dt          |           j         dt          |           j         d| j         dS )N<.z (session="z")>)typerh   rg   rw   r   s    r,   __repr__zWebDriver.__repr__   s7    _4::(__4::+>__4?____r+   c                     | S Nr*   r   s    r,   	__enter__zWebDriver.__enter__   s    r+   exc_typeexc	tracebackc                 .    |                                   d S r   )quit)r   r   r   r   s       r,   __exit__zWebDriver.__exit__   s     			r+   c              /      K   d}t          | j        |          s| j        } ||i || _        	 dV  |r	|| _        dS dS # |r|| _        w xY w)a  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.
        N)rq   ro   )r   file_detector_classargskwargslast_detectors        r,   file_detector_contextzWebDriver.file_detector_context   s      $ $,.ABB 	F .M!4!4d!Ef!E!ED	3EEE 3%2"""3 3} 3%2"2222s   A   Ac                     | j         S r   )r{   r   s    r,   mobilezWebDriver.mobile  s
    |r+   c                 L    d| j         v r| j         d         S t          d          )zReturns the name of the underlying browser for this instance.

        :Usage:
            ::

                name = driver.name
        r@   z1browserName not specified in session capabilities)r5   KeyErrorr   s    r,   namezWebDriver.name  s-     DI%%9]++JKKKr+   c                     dS )zxCalled before starting a new session.

        This method may be overridden to define custom startup behavior.
        Nr*   r   s    r,   r}   zWebDriver.start_client  s	    
 	r+   c                     dS )zCalled after executing a quit command.

        This method may be overridden to define custom shutdown
        behavior.
        Nr*   r   s    r,   stop_clientzWebDriver.stop_client  s	     	r+   r/   c                     t          |          }|                     t          j        |          d         }|                    d          | _        |                    d          | _        dS )zCreates a new session with the desired capabilities.

        :Args:
         - capabilities - a capabilities dict to start the session with.
        value	sessionIdr/   N)r9   executer   NEW_SESSIONrB   rw   r5   )r   r/   r5   responses       r,   r~   zWebDriver.start_session#  sV     L))<< 3T::7C",,{33LL00			r+   c                 v    t          |t                    r6i }|                                D ]\  }}                     |          ||<   |S t          | j                  r	d|j        iS t          | j                  r	d|j        iS t          |t                    rt           fd|D                       S |S )N#element-6066-11e4-a52e-4f735466cecf"shadow-6066-11e4-a52e-4f735466cecfc              3   B   K   | ]}                     |          V  d S r   )_wrap_valuerC   itemr   s     r,   rE   z(WebDriver._wrap_value.<locals>.<genexpr>:  s1      AA4((..AAAAAAr+   )rq   dictr4   r   _web_element_clsid_shadowroot_clsrr   )r   r   	convertedkeyvals   `    r,   r   zWebDriver._wrap_value/  s    eT"" 	I!KKMM 7 7S!%!1!1#!6!6	#eT233 	E958DDeT122 	D8%(CCeT"" 	BAAAA5AAAAAAr+   
element_idc                 .    |                      | |          S )z6Creates a web element with the specified `element_id`.)r   )r   r   s     r,   create_web_elementzWebDriver.create_web_element=  s    $$T:666r+   c                 x    t          |t                    rsd|v r                     |d                   S d|v r                      |d                   S |                                D ]\  }}                     |          ||<   |S t          |t                    rt           fd|D                       S |S )Nr   r   c              3   B   K   | ]}                     |          V  d S r   )_unwrap_valuer   s     r,   rE   z*WebDriver._unwrap_value.<locals>.<genexpr>K  s1      CCT**400CCCCCCr+   )rq   r   r   r   r4   r   rr   )r   r   r   r   s   `   r,   r   zWebDriver._unwrap_valueA  s    eT"" 	4==..u5Z/[\\\3u<<++D%8\2]^^^!KKMM 5 5S!//44c

LeT"" 	DCCCCUCCCCCCr+   driver_commandparamsc                 N   |                      |          }| j        r|s
d| j        i}nd|vr
| j        |d<   | j                            ||          }|rH| j                            |           |                     |                    dd                    |d<   |S dd| j        dS )aH  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.
        r   r   Nr   )successr   r   )r   rw   rM   r   ry   check_responser   rB   )r   r   r   r   s       r,   r   zWebDriver.executeN  s     !!&))? 	6 6%t7F**&*o{#(00HH 	--h777 $ 2 28<<3N3N O OHWO t$/JJJr+   urlc                 J    |                      t          j        d|i           dS )z0Loads a web page in the current browser session.r   N)r   r   GET)r   r   s     r,   rB   zWebDriver.geti  s"    W[5#,/////r+   c                 h    |                      t          j                                      dd          S )zuReturns the title of the current page.

        :Usage:
            ::

                title = driver.title
        r    )r   r   	GET_TITLErB   r   s    r,   titlezWebDriver.titlem  s)     ||G-..227B???r+   scriptc                 B    t          |          }|| j        |j        <   |S )zUStore common javascript scripts to be executed later by a unique
        hashable ID.)r#   rx   r   )r   r   
script_keyscript_key_instances       r,   
pin_scriptzWebDriver.pin_scriptx  s)     (
336</23""r+   r   c                     	 | j                             |j                   dS # t          $ r t          d| d| j                    dw xY w)z$Remove a pinned script from storage.zNo script with key: z existed in N)rx   popr   r   )r   r   s     r,   unpinzWebDriver.unpin  sk    	k##JM22222 	k 	k 	k_*__$J]__``fjj	ks	   # &A	c                 *    t          | j                  S r   )rr   rx   r   s    r,   get_pinned_scriptszWebDriver.get_pinned_scripts  s    D'(((r+   c                    t          |t                    r1	 | j        |j                 }n# t          $ r t          d          w xY wt          |          }t          j        }| 	                    |||d          d         S )a'  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;')
        z Pinned script could not be foundr   r   r   )
rq   r#   rx   r   r   r   rr   r   W3C_EXECUTE_SCRIPTr   r   r   r   converted_argscommands        r,   execute_scriptzWebDriver.execute_script  s     fi(( 	NN,VY7 N N N)*LMMMN d,||G%O%OPPQXYYs	   * Ac                 v    t          |          }t          j        }|                     |||d          d         S )a  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)
        r   r   )rr   r   W3C_EXECUTE_SCRIPT_ASYNCr   r   s        r,   execute_async_scriptzWebDriver.execute_async_script  s9     d2||G%O%OPPQXYYr+   c                 L    |                      t          j                  d         S )znGets the URL of the current page.

        :Usage:
            ::

                driver.current_url
        r   )r   r   GET_CURRENT_URLr   s    r,   current_urlzWebDriver.current_url       ||G344W==r+   c                 L    |                      t          j                  d         S )zqGets the source of the current page.

        :Usage:
            ::

                driver.page_source
        r   )r   r   GET_PAGE_SOURCEr   s    r,   page_sourcezWebDriver.page_source  r   r+   c                 D    |                      t          j                   dS )zcCloses the current window.

        :Usage:
            ::

                driver.close()
        N)r   r   CLOSEr   s    r,   closezWebDriver.close  s     	W]#####r+   c                    	 |                      t          j                   |                                  | j                                         dS # |                                  | j                                         w xY w)z|Quits the driver and closes every associated window.

        :Usage:
            ::

                driver.quit()
        N)r   r   QUITr   rM   r   r   s    r,   r   zWebDriver.quit  sx    	*LL&&&!''))))) !''))))s   A /A?c                 L    |                      t          j                  d         S )zReturns the handle of the current window.

        :Usage:
            ::

                driver.current_window_handle
        r   )r   r   W3C_GET_CURRENT_WINDOW_HANDLEr   s    r,   current_window_handlezWebDriver.current_window_handle  s     ||GABB7KKr+   c                 L    |                      t          j                  d         S )zReturns the handles of all windows within the current session.

        :Usage:
            ::

                driver.window_handles
        r   )r   r   W3C_GET_WINDOW_HANDLESr   s    r,   window_handleszWebDriver.window_handles       ||G:;;GDDr+   c                 J    t           j        }|                     |d           dS )z5Maximizes the current window that webdriver is using.N)r   W3C_MAXIMIZE_WINDOWr   )r   r   s     r,   maximize_windowzWebDriver.maximize_window  s$    -Wd#####r+   c                 D    |                      t          j                   dS )z<Invokes the window manager-specific 'full screen' operation.N)r   r   FULLSCREEN_WINDOWr   s    r,   fullscreen_windowzWebDriver.fullscreen_window  s    W./////r+   c                 D    |                      t          j                   dS )z9Invokes the window manager-specific 'minimize' operation.N)r   r   MINIMIZE_WINDOWr   s    r,   minimize_windowzWebDriver.minimize_window   s    W,-----r+   print_optionsc                 ~    i }|r|                                 }|                     t          j        |          d         S )zTakes PDF of the current page.

        The driver makes a best effort to return a PDF based on the
        provided parameters.
        r   )to_dictr   r   
PRINT_PAGE)r   r   rR   s      r,   
print_pagezWebDriver.print_page  s>      	.#++--G||G.88AAr+   c                     | j         S )a<  
        :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')
        )rz   r   s    r,   	switch_tozWebDriver.switch_to  s    $ r+   c                 D    |                      t          j                   dS )zvGoes one step backward in the browser history.

        :Usage:
            ::

                driver.back()
        N)r   r   GO_BACKr   s    r,   backzWebDriver.back%       	W_%%%%%r+   c                 D    |                      t          j                   dS )zxGoes one step forward in the browser history.

        :Usage:
            ::

                driver.forward()
        N)r   r   
GO_FORWARDr   s    r,   forwardzWebDriver.forward/  s     	W'(((((r+   c                 D    |                      t          j                   dS )zfRefreshes the current page.

        :Usage:
            ::

                driver.refresh()
        N)r   r   REFRESHr   s    r,   refreshzWebDriver.refresh9  r   r+   c                 L    |                      t          j                  d         S )zReturns a set of dictionaries, corresponding to cookies visible in
        the current session.

        :Usage:
            ::

                driver.get_cookies()
        r   )r   r   GET_ALL_COOKIESr   s    r,   get_cookieszWebDriver.get_cookiesD  r   r+   c                     t          j        t                    5  |                     t          j        d|i          d         cddd           S # 1 swxY w Y   dS )zGet a single cookie by name. Returns the cookie if found, None if
        not.

        :Usage:
            ::

                driver.get_cookie('my_cookie')
        r   r   N)
contextlibsuppressr   r   r   
GET_COOKIEr   r   s     r,   
get_cookiezWebDriver.get_cookieO  s      !677 	M 	M<< 2VTNCCGL	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	Mts   (AAAc                 J    |                      t          j        d|i           dS )zDeletes a single cookie with the given name.

        :Usage:
            ::

                driver.delete_cookie('my_cookie')
        r   N)r   r   DELETE_COOKIEr  s     r,   delete_cookiezWebDriver.delete_cookie\  s%     	W*VTN;;;;;r+   c                 D    |                      t          j                   dS )zDelete all cookies in the scope of the session.

        :Usage:
            ::

                driver.delete_all_cookies()
        N)r   r   DELETE_ALL_COOKIESr   s    r,   delete_all_cookieszWebDriver.delete_all_cookiesf  s     	W/00000r+   c                     d|v r0|d         dv sJ |                      t          j        d|i           dS |                      t          j        d|i           dS )ag  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'})
        sameSite)StrictLaxNonecookieN)r   r   
ADD_COOKIE)r   cookie_dicts     r,   
add_cookiezWebDriver.add_cookiep  sj     $$z*.GGGGGLL+h-DEEEEELL+h-DEEEEEr+   time_to_waitc           	          |                      t          j        dt          t	          |          dz            i           dS )a  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)
        implicit  Nr   r   SET_TIMEOUTSintfloatr   r  s     r,   implicitly_waitzWebDriver.implicitly_wait  s<     	W)JE,<O<ORV<V8W8W+XYYYYYr+   c           	          |                      t          j        dt          t	          |          dz            i           dS )a!  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)
        r   r"  Nr#  r'  s     r,   set_script_timeoutzWebDriver.set_script_timeout  s<     	W)Hc%:M:MPT:T6U6U+VWWWWWr+   c           	         	 |                      t          j        dt          t	          |          dz            i           dS # t
          $ r7 |                      t          j        t	          |          dz  dd           Y dS w xY w)zSet 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)
        pageLoadr"  z	page load)msr   N)r   r   r$  r%  r&  r   r'  s     r,   set_page_load_timeoutzWebDriver.set_page_load_timeout  s    	hLL-
Cl@S@SVZ@Z<[<[/\]]]]]! 	h 	h 	hLL-eL6I6ID6PZe/f/fgggggg	hs   ?A =BBc                    |                      t          j                  d         }|                    d          dz  |d<   |                    d          dz  |d<   |                    d          dz  |d<   t	          di |S )	zGet all the timeouts that have been set on the current session.

        :Usage:
            ::

                driver.timeouts
        :rtype: Timeout
        r   r!  r"  implicit_waitr,  	page_loadr   r*   )r   r   GET_TIMEOUTSr   r   )r   timeoutss     r,   r3  zWebDriver.timeouts  s     << 455g>$,LL$<$<t$C! (Z 8 84 ?%\\(33d:##(###r+   c                 v    |                      t          j        |                                          d         }dS )a  Set all timeouts for the session. This will override any previously
        set timeouts.

        :Usage:
            ::
                my_timeouts = Timeouts()
                my_timeouts.implicit_wait = 10
                driver.timeouts = my_timeouts
        r   N)r   r   r$  _to_json)r   r3  _s      r,   r3  zWebDriver.timeouts  s/     LL-x/@/@/B/BCCGLr+   r   c                    t          |t                    r8|                     ||          }|st          d|j                   |d         S |t
          j        k    rt
          j        }d| d}nD|t
          j        k    rt
          j        }d| }n"|t
          j	        k    rt
          j        }d| d}| 
                    t          j        ||d          d	         S )
zFind an element given a By strategy and locator.

        :Usage:
            ::

                element = driver.find_element(By.ID, 'foo')

        :rtype: WebElement
        )byr   z%Cannot locate relative element with: r   [id=""]r   [name="usingr   r   )rq   r   find_elementsr   rootr   IDCSS_SELECTOR
CLASS_NAMENAMEr   r   FIND_ELEMENT)r   r8  r   elementss       r,   find_elementzWebDriver.find_element  s     b*%% 	))Ru)==H `,-^UWU\-^-^___A;;;B%E%%%EE2=  BKKEE27]]B'e'''E||G0B2O2OPPQXYYr+   c                 f   t          |t                    rd                    t                              d          dd                   }t          j        |d                              d          }d| d}|                     ||	                                          S |t          j        k    rt          j        }d| d	}nD|t          j        k    rt          j        }d| }n"|t          j        k    rt          j        }d
| d	}|                     t           j        ||d          d         pg S )zFind elements given a By strategy and locator.

        :Usage:
            ::

                elements = driver.find_elements(By.CLASS_NAME, 'foo')

        :rtype: list of WebElement
        r   NzfindElements.jsutf8z/* findElements */return (z).apply(null, arguments);r9  r:  r;  r<  r   )rq   r   joinrg   splitpkgutilget_datadecoder   r   r   r@  rA  rB  rC  r   r   FIND_ELEMENTS)r   r8  r   _pkgraw_functionfind_element_jss         r,   r>  zWebDriver.find_elements  s     b*%% 	F88HNN3//455D"+D2CDDKKFSSLb<bbbO&&

EEE;;B%E%%%EE2=  BKKEE27]]B'e'''E ||G1R%3P3PQQRYZ`^``r+   c                     | j         S )z4Returns the drivers current capabilities being used.)r5   r   s    r,   r/   zWebDriver.capabilities  s     yr+   c                    t          |                                                              d          st          j        dt
          d           |                                 }	 t          |d          5 }|                    |           ddd           n# 1 swxY w Y   n# t          $ r Y ~dS w xY w~n# ~w xY wdS )	a  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')
        z.pngz^name used for saved screenshot does not match file type. It should end with a `.png` extension   
stacklevelwbNFT)
rt   lowerendswithwarningswarnUserWarningget_screenshot_as_pngopenwriteOSError)r   filenamepngfs       r,   get_screenshot_as_filez WebDriver.get_screenshot_as_file  s    8}}""$$--f55 	Mp   
 ((**	h%%                	 	 		 GGGGtsN   &B$ 6BB$ BB$ B B$ #B8 $
B3.B8 2B33B8 8B;c                 ,    |                      |          S )a  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')
        )re  )r   rb  s     r,   save_screenshotzWebDriver.save_screenshot/  s     **8444r+   c                 j    t          |                                                     d                    S )zGets the screenshot of the current window as a binary data.

        :Usage:
            ::

                driver.get_screenshot_as_png()
        ascii)r   get_screenshot_as_base64encoder   s    r,   r^  zWebDriver.get_screenshot_as_png?  s,     6688??HHIIIr+   c                 L    |                      t          j                  d         S )zGets 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()
        r   )r   r   
SCREENSHOTr   s    r,   rj  z"WebDriver.get_screenshot_as_base64I  s     ||G.//88r+   currentwindowHandlec                     |                      |           |                     t          |          t          |                     dS )a$  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)
        widthheightN"_check_if_window_handle_is_currentset_window_rectr%  )r   rr  rs  ro  s       r,   set_window_sizezWebDriver.set_window_sizeT  sC     	//===3u::c&kkBBBBBr+   c                     |                      |           |                                                     dd          rd         fddD             S )zGets the width and height of the current window.

        :Usage:
            ::

                driver.get_window_size()
        r   Nc                 "    i | ]}||         S r*   r*   )rC   r7   sizes     r,   
<dictcomp>z-WebDriver.get_window_size.<locals>.<dictcomp>r  s    888q47888r+   rq  )ru  get_window_rectrB   )r   ro  rz  s     @r,   get_window_sizezWebDriver.get_window_sizec  sd     	//===##%%88GT"" 	!=D8888$78888r+   xyc                     |                      |           |                     t          |          t          |                    S )a.  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)
        r~  r  rt  )r   r~  r  ro  s       r,   set_window_positionzWebDriver.set_window_positiont  s=     	//===##c!ffA#777r+   c                 r    |                      |           |                                 fddD             S )zGets the x,y position of the current window.

        :Usage:
            ::

                driver.get_window_position()
        c                 "    i | ]}||         S r*   r*   )rC   r7   positions     r,   r{  z1WebDriver.get_window_position.<locals>.<dictcomp>  s    33318A;333r+   r  )ru  r|  )r   ro  r  s     @r,   get_window_positionzWebDriver.get_window_position  sD     	//===''))3333
3333r+   c                 B    |dk    rt          j        dd           dS dS )z5Warns if the window handle is not equal to `current`.rn  z?Only 'current' window is supported for W3C compatible browsers.rU  rV  N)r[  r\  )r   ro  s     r,   ru  z,WebDriver._check_if_window_handle_is_current  s2    9$$M[hijjjjjj %$r+   c                 L    |                      t          j                  d         S )zGets the x, y coordinates of the window as well as height and width
        of the current window.

        :Usage:
            ::

                driver.get_window_rect()
        r   )r   r   GET_WINDOW_RECTr   s    r,   r|  zWebDriver.get_window_rect  r   r+   c                     |||s|st          d          |                     t          j        ||||d          d         S )a  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)
        Nz'x and y or height and width need values)r~  r  rr  rs  r   )r   r   r   SET_WINDOW_RECT)r   r~  r  rr  rs  s        r,   rv  zWebDriver.set_window_rect  sN     I!)f)U)*+TUUU||G311u`f5g5ghhipqqr+   c                     | j         S r   )_file_detectorr   s    r,   ro   zWebDriver.file_detector  s    ""r+   c                 ~    |st          d          t          |t                    st          d          || _        dS )a0  Set the file detector to be used when sending keyboard input. By
        default, this is set to a file detector that does nothing.

        see FileDetector
        see LocalFileDetector
        see UselessFileDetector

        :Args:
         - detector: The detector to use. Must not be None.
        z,You may not set a file detector that is nullz+Detector has to be instance of FileDetectorN)r   rq   r   r  )r   detectors     r,   ro   zWebDriver.file_detector  sL      	U$%STTT(L11 	T$%RSSS&r+   c                 L    |                      t          j                  d         S )zGets the current orientation of the device.

        :Usage:
            ::

                orientation = driver.orientation
        r   )r   r   GET_SCREEN_ORIENTATIONr   s    r,   orientationzWebDriver.orientation  r   r+   c                     ddg}|                                 |v r$|                     t          j        d|i           dS t	          d          )zSets the current orientation of the device.

        :Args:
         - value: orientation to set it to.

        :Usage:
            ::

                driver.orientation = 'landscape'
        	LANDSCAPEPORTRAITr  z>You can only set the orientation to 'LANDSCAPE' and 'PORTRAIT'N)upperr   r   SET_SCREEN_ORIENTATIONr   )r   r   allowed_valuess      r,   r  zWebDriver.orientation  sR     &z2;;==N**LL7-9OPPPPP$%efffr+   c                 L    |                      t          j                  d         S )zGets a list of the available log types. This only works with w3c
        compliant browsers.

        :Usage:
            ::

                driver.log_types
        r   )r   r   GET_AVAILABLE_LOG_TYPESr   s    r,   	log_typeszWebDriver.log_types  s     ||G;<<WEEr+   c                 R    |                      t          j        d|i          d         S )a>  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')
        r   r   )r   r   GET_LOG)r   log_types     r,   get_logzWebDriver.get_log  s$     ||GOfh-?@@IIr+   c                    | j         rt          | j         fS t                       t          s| j                            d          rN| j                            d          }| j                            d                              d          d         }n|                                 \  }}|st          d          t          	                    |          at          |          | _         | j                             t          j                                                  }|d         j        }| j                             t          j                            |d                    }|| j         _        t          | j         fS )Nse:cdpse:cdpVersionr   r   2Unable to find url to connect to from capabilitiesT)r   devtoolsr-   r5   rB   rK  _get_cdp_detailsr   r)   import_devtoolsr'   r   targetget_targets	target_idattach_to_targetrw   )r   ws_urlversiontargetsr  sessions         r,   start_devtoolszWebDriver.start_devtools  sB   % 	8T777 LLL 
89==** >!Y]]844F"immO<<BB3GGJGG&*&;&;&=&=OGV c,-abbb..w77)<V)D)DD&0889T9T9V9VWWG
,I0889Y9YZcei9j9jkkG4;D&1T777r+   c                2  K   t                       | j                            d          rN| j                            d          }| j                            d                              d          d         }n|                                 \  }}|st          d          t                              |          }t                              |          4 d {V }|	                    |j
                                                   d {V }|d         j        }|                    |          4 d {V }t          |t          |          W V  d d d           d {V  n# 1 d {V swxY w Y   d d d           d {V  d S # 1 d {V swxY w Y   d S )Nr  r  r   r   r  )r-   r5   rB   rK  r  r   r)   r  open_cdpr   r  r  r  open_sessionr   )r   r  r  r  connr  r  r  s           r,   bidi_connectionzWebDriver.bidi_connection  s      	9=="" 	6Y]]8,,FimmO44::3??BGG"3355OGV 	[$%YZZZ&&w//<<'' 	= 	= 	= 	= 	= 	= 	=4 LL)D)D)F)FGGGGGGGGG
,I((33 = = = = = = =w$Wc8<<<<<<= = = = = = = = = = = = = = = = = = = = = = = = = = =	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=s7   AF6E"F"
E,	,F/E,	0F
FFc                     | j         s|                                  | j        st          | j                   | _        | j        S r   )r   _start_bidir   r   r   s    r,   r   zWebDriver.script1  sC    ) 	| 	>!$"<==DL|r+   c                     | j                             d          r| j                             d          }nt          d          t          |          | _        d S )NwebSocketUrlr  )r5   rB   r   r'   r   )r   r  s     r,   r  zWebDriver._start_bidi;  sS    9==(( 	[Y]]>22FF$%YZZZ%8%@%@"""r+   c                    dd l }dd l}|                                }d}| j                            d          dk    r.| j                            d                              d          }nh| j                            d          dk    r.| j                            d                              d          }nd	}| j                            d
          }|                    dd| d          }|                    |j                  }|                    d          }|                    d          }	dd l}
|rd}n)|
	                    d|          
                    d          }||	fS )Nr   Fr@   chromezgoog:chromeOptionsdebuggerAddressMicrosoftEdgezms:edgeOptionsTzmoz:debuggerAddressr   zhttp://z/json/versionBrowserwebSocketDebuggerUrlU   z
.*/(\d+)\.r   )jsonurllib3PoolManagerr5   rB   requestloadsdataresearchgroup)r   r  r  http_firefoxdebugger_addressresr  browser_versionwebsocket_urlr  r  s               r,   r  zWebDriver._get_cdp_detailsC  sa   ""$$9==''833#y}}-ABBFFGXYYY]]=))_<<#y}}-=>>BBCTUUH#y}}-BCCll5"K,<"K"K"KLLzz#(##((9--!788			 	I GGii??EEaHHG%%r+   c                     |                      t          j        |                                          d         | _        dS )z4Adds a virtual authenticator with the given options.r   N)r   r   ADD_VIRTUAL_AUTHENTICATORr   r|   )r   rR   s     r,   add_virtual_authenticatorz#WebDriver.add_virtual_authenticatorc  s4    !%g.OQXQ`Q`QbQb!c!cdk!lr+   c                     | j         S )z,Returns the id of the virtual authenticator.)r|   r   s    r,   virtual_authenticator_idz"WebDriver.virtual_authenticator_idg  s     %%r+   c                 b    |                      t          j        d| j        i           d| _        dS )zRemoves a previously added virtual authenticator.

        The authenticator is no longer valid after removal, so no
        methods may be called.
        authenticatorIdN)r   r   REMOVE_VIRTUAL_AUTHENTICATORr|   r   s    r,   remove_virtual_authenticatorz&WebDriver.remove_virtual_authenticatorl  s2     	W9<MtOe;fggg!%r+   
credentialc                     |                      t          j        i |                                d| j        i           dS )z,Injects a credential into the authenticator.r  N)r   r   ADD_CREDENTIALr   r|   )r   r  s     r,   add_credentialzWebDriver.add_credentialv  sB     	W+-p
0B0B0D0D-pFWY]Yo-p-pqqqqqr+   c                 t    |                      t          j        d| j        i          }d |d         D             S )z;Returns the list of credentials owned by the authenticator.r  c                 6    g | ]}t          j        |          S r*   )r   	from_dict)rC   r  s     r,   
<listcomp>z-WebDriver.get_credentials.<locals>.<listcomp>  s#    \\\Z
$Z00\\\r+   r   )r   r   GET_CREDENTIALSr|   )r   credential_datas     r,   get_credentialszWebDriver.get_credentials{  s>     ,,w'>ARTXTj@kll\\?SZC[\\\\r+   credential_idc                     t          |t                    r!t          |                                          }|                     t
          j        || j        d           dS )z,Removes a credential from the authenticator.)credentialIdr  N)rq   	bytearrayr   rN  r   r   REMOVE_CREDENTIALr|   )r   r  s     r,   remove_credentialzWebDriver.remove_credential  sd     mY// 	F-m<<CCEEM%Z^Zp'q'q	
 	
 	
 	
 	
r+   c                 T    |                      t          j        d| j        i           dS )z/Removes all credentials from the authenticator.r  N)r   r   REMOVE_ALL_CREDENTIALSr|   r   s    r,   remove_all_credentialsz WebDriver.remove_all_credentials  s*     	W36GI_5`aaaaar+   verifiedc                 V    |                      t          j        | j        |d           dS )zSets whether the authenticator will simulate success or fail on user
        verification.

        verified: True if the authenticator will pass user verification, False otherwise.
        )r  isUserVerifiedN)r   r   SET_USER_VERIFIEDr|   )r   r  s     r,   set_user_verifiedzWebDriver.set_user_verified  s-     	W.DDZnv0w0wxxxxxr+   c                     d| j         vrt          d          |                     t          j                  d         d         S )z]Retrieves the downloadable files as a map of file names and their
        corresponding URLs.se:downloadsEnabledCYou must enable downloads in order to work with downloadable files.r   names)r/   r   r   r   GET_DOWNLOADABLE_FILESr   s    r,   get_downloadable_filesz WebDriver.get_downloadable_files  s@     !(999$%jkkk||G:;;GDWMMr+   	file_nametarget_directoryc                    d| j         vrt          d          t          j                            |          st          j        |           |                     t          j        d|i          d         d         }t          j
                    5 }t          j                            ||dz             }t          |d          5 }|                    t          j        |                     ddd           n# 1 swxY w Y   t!          j        |d	          5 }|                    |           ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )
zDownloads 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.
        r  r  r   r   contentsz.ziprX  Nr)r/   r   ospathexistsmakedirsr   r   DOWNLOAD_FILEtempfileTemporaryDirectoryrJ  r_  r`  base64r   zipfileZipFile
extractall)r   r  r  r  tmp_dirzip_filefilezip_refs           r,   download_filezWebDriver.download_file  s    !(999$%jkkkw~~.// 	*K()))<< 5	7JKKGTU_`(** 	5gw||GY-?@@Hh%% 7

6+H556667 7 7 7 7 7 7 7 7 7 7 7 7 7 7 3// 57""#34445 5 5 5 5 5 5 5 5 5 5 5 5 5 5	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5sZ   4E(C5)E5C9	9E<C9	=ED7+E7D;	;E>D;	?EEEc                 t    d| j         vrt          d          |                     t          j                   dS )zDeletes all downloadable files.r  r  N)r/   r   r   r   DELETE_DOWNLOADABLE_FILESr   s    r,   delete_downloadable_filesz#WebDriver.delete_downloadable_files  s:     (999$%jkkkW677777r+   )rn   TNNr   )rS   N)rn  )NNNN)vrg   rh   ri   rj   r&   r   r$   r   r   rt   r"   boolr   r   r   r
   r   r   r   typingTypeBaseExceptiontypesTracebackTyper   r   r   propertyr!   r   r   r}   r   r   r~   r   r   r   r   rB   r   r#   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r%   r   r   r  r  r	  r	   r  r  r  r  r&  r(  r*  r.  r   r3  setterr   r@  rF  r>  r/   re  rg  ru   r^  rj  rw  r}  r  r  ru  r|  rv  ro   r  r  r  r  r   r  r   r  r  r   r  r  r   r  r   r  r  r  r  r  r  r  r  r  r*   r+   r,   rm   rm      s.       
 
 " O :Q04CG/ /%5 56/ /  -	/
 %T+-> >?@/ 
/ / / /b` ` `  /&+m"<= _]+ ?5#67	    3 3 ^36     X 
Lc 
L 
L 
L X
L    
1$ 
14 
1 
1 
1 
1  7S 7Z 7 7 7 7  K Kc K4 K4 K K K K60s 0t 0 0 0 0 @s @ @ @ X@# # #) # # # #k	 kd k k k k)DI ) ) ) )Z Z Z.Z3 Z Z Z Z& >S > > > X> >S > > > X>$ $ $ $* * * * Ls L L L XL ES	 E E E XE$ $ $ $
0 0 0 0. . . .
B 
B(> 
B# 
B 
B 
B 
B 8    X(& & & &) ) ) )& & & &	>T$Z 	> 	> 	> 	>&/&+">    < < < <1 1 1 1F F F F,ZE Zd Z Z Z Z Xu X X X X Xh% hD h h h h" $( $ $ $ X$ _
M 
M 
M _
M !eD Z ZHSM ZZ Z Z Z Z8  "uT a aXc] ad:FV a a a a< d    X$    <54 5 5 5 5 Ju J J J J	9# 	9 	9 	9 	9C C3 Ct C C C C9 9C 9 9 9 9 9"8 8U 8u 8C 8X\ 8 8 8 84 4T 4 4 4 4ks kt k k k k
	> 	> 	> 	> 	>r r$ r r r r& #| # # # X# ' ' ' '" E E XE g g g g" 	F 	F X	FJ J J 8 8 84 = = =&   XA A A& & &@m1L mQU m m m m &# & & & X& $& & & $#& $r r r r r $#r $]j!1 ] ] ] $#]
 $
uS)^/D 
 
 
 
 $#
 $b b b $#b $y$ y4 y y y $#yN N N N N5s 5c 5d 5 5 5 5.8 8 8 8 8 8r+   rm   )F)Lrj   r  r  r2   r  rL  r  r  r  r[  r  abcr   r   r   r   r   	importlibr   r	   r
   r   r   selenium.common.exceptionsr   r   r   r   r   %selenium.webdriver.common.bidi.scriptr   selenium.webdriver.common.byr   !selenium.webdriver.common.optionsr   ,selenium.webdriver.common.print_page_optionsr   "selenium.webdriver.common.timeoutsr   /selenium.webdriver.common.virtual_authenticatorr   r   r   +selenium.webdriver.support.relative_locatorr   r  r   r   r   errorhandlerr   ro   r   r    r   r!   remote_connectionr"   r   r#   
shadowrootr$   r   r%   
webelementr&   websocket_connectionr'   r)   r  r-   r9   rQ   rd   rf   rm   r*   r+   r,   <module>r&     s  " $ #       				                   $ $ $ $ $ $ * * * * * * % % % % % % # # # # # #                         ? ? ? ? ? ? : : : : : : < < < < < < = = = = = = 9 9 9 9 9 9 8 8 8 8 8 8 + + + + + + 9 9 9 9 9 9 E E E E E E 7 7 7 7 7 7 F F F F F F W W W W W W      C B B B B B + + + + + +       & & & & & & ' ' ' ' ' ' , , , , , ,       / / / / / / ! ! ! ! ! ! " " " " " "       " " " " " " 5 5 5 5 5 5
B B BO O O&	] 	] 	] 	]D- $    D    g    f8 f8 f8 f8 f8 f8 f8 f8 f8 f8r+   