
    gW              	       	   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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  e j.                  e      Zi ej4                  dej6                  dej8                  dej:                  dej<                  dej>                  dej@                  dejB                  dejD                  dejF                  dejH                  dejJ                  dejL                  dejN                  dejP                  dejR                  dejT                  di ejV                  dejX                  dejZ                  dej\                  d ej^                  d!ej`                  d"ejb                  d#ejd                  d$ejf                  d%ejh                  d&ejj                  d'ejl                  d(ejn                  d)ejp                  d*ejr                  d+ejt                  d,ejv                  d-i ejx                  d.ejz                  d/ej|                  d0ej~                  d1ej                  d2ej                  d3ej                  d4ej                  d5ej                  d6ej                  d7ej                  d8ej                  d9ej                  d:ej                  d;ej                  d<ej                  d=ej                  d>i ej                  d?ej                  d@ej                  dAej                  dBej                  dCej                  dDej                  dEej                  dFej                  dGej                  dHej                  dIej                  dJej                  dKej                  dLej                  dMej                  dNej                  dOi ej                  dPej                  dQej                  dRej                  dSej                  dTej                  dUej                  dVej                  dWej                  dXej                  dYej                  dZej                  d[ej                  d\ej                  d]ej                  d^ej                  d_ej                  d`ej                  daej                  dbej                  dcej                  ddiZs G de df      Zty)g    N)	b64encode)Optional)parse)urlparse)__version__   )utils)ClientConfig)Command)	ErrorCode)POSTz/session)DELETEz/session/$sessionId)GET/session/$sessionId/window)r   z"/session/$sessionId/window/handles)r   /session/$sessionId/url)r   z/session/$sessionId/forward)r   z/session/$sessionId/back)r   z/session/$sessionId/refresh)r   z /session/$sessionId/execute/sync)r   z!/session/$sessionId/execute/async)r   r   )r   z/session/$sessionId/title)r   z/session/$sessionId/source)r   z/session/$sessionId/screenshot)r   z*/session/$sessionId/element/$id/screenshot)r   z/session/$sessionId/element)r   z/session/$sessionId/elements)r   z"/session/$sessionId/element/active)r   z'/session/$sessionId/element/$id/element)r   z(/session/$sessionId/element/$id/elements)r   z%/session/$sessionId/element/$id/click)r   z%/session/$sessionId/element/$id/clear)r   z$/session/$sessionId/element/$id/text)r   z%/session/$sessionId/element/$id/value)r   z$/session/$sessionId/element/$id/name)r   z(/session/$sessionId/element/$id/selected)r   z'/session/$sessionId/element/$id/enabled)r   z$/session/$sessionId/element/$id/rect)r   z//session/$sessionId/element/$id/attribute/$name)r   z./session/$sessionId/element/$id/property/$name)r   z,/session/$sessionId/element/$id/computedrole)r   z-/session/$sessionId/element/$id/computedlabel)r   z&/session/$sessionId/element/$id/shadow)r   z,/session/$sessionId/shadow/$shadowId/element)r   z-/session/$sessionId/shadow/$shadowId/elements)r   /session/$sessionId/cookie)r   r   )r    /session/$sessionId/cookie/$name)r   r   )r   r   )r   z/session/$sessionId/frame)r   z /session/$sessionId/frame/parent)r   r   )r   z/session/$sessionId/window/new)r   r   )r   z1/session/$sessionId/element/$id/css/$propertyName)r   z!/session/$sessionId/execute_async)r   /session/$sessionId/timeouts)r   r   )r   z!/session/$sessionId/alert/dismiss)r   z /session/$sessionId/alert/accept)r   /session/$sessionId/alert/text)r   r   )r   /session/$sessionId/actions)r   r   )r   /session/$sessionId/window/rect)r   r   )r   z#/session/$sessionId/window/maximize)r   /session/$sessionId/orientation)r   r   )r   &/session/$sessionId/network_connection)r   r   )r   z/session/$sessionId/se/log)r   z /session/$sessionId/se/log/types)r   /session/$sessionId/context)r   z/session/$sessionId/contexts)r   r   )r   z%/session/$sessionId/window/fullscreen)r   z#/session/$sessionId/window/minimize)r   z/session/$sessionId/print)r   z*/session/$sessionId/webauthn/authenticator)r   z;/session/$sessionId/webauthn/authenticator/$authenticatorId)r   zF/session/$sessionId/webauthn/authenticator/$authenticatorId/credential)r   G/session/$sessionId/webauthn/authenticator/$authenticatorId/credentials)r   zU/session/$sessionId/webauthn/authenticator/$authenticatorId/credentials/$credentialId)r   r   )r   z>/session/$sessionId/webauthn/authenticator/$authenticatorId/uv)r   z/session/$sessionId/se/file)r   /session/$sessionId/se/files)r   r   )r   r   )r   z"/session/$sessionId/fedcm/gettitle)r   z'/session/$sessionId/fedcm/getdialogtype)r   z%/session/$sessionId/fedcm/accountlist)r   z+/session/$sessionId/fedcm/clickdialogbutton)r   z&/session/$sessionId/fedcm/canceldialog)r   z'/session/$sessionId/fedcm/selectaccount)r   z)/session/$sessionId/fedcm/setdelayenabled)r   z'/session/$sessionId/fedcm/resetcooldownc                      e Zd ZU dZdZddlZddlZddlZej                  d      , e	ej                  d e
ej                                           nej                         Zdej                  v rej                  d      nej                         ZdZeed<    ej(                         j+                         Zedk(  rdZdZd	e d
e dZed        Zed        Zed        Zed        Zed        Zed#d       Zd Z d Z!d Z"	 	 	 	 	 	 d$de#e
   de#e$   de#e$   de#e$   de#e%   de#e   fdZ&i Z'd Z(de
fdZ)d Z*d%d Z+d! Z,d&d"Z-y)'RemoteConnectionzA connection with the Remote WebDriver server.

    Communicates with the server using the WebDriver wire protocol:
    https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol
    Nr   GLOBAL_DEFAULT_TIMEOUTREQUESTS_CA_BUNDLE_client_configdarwinmacz	selenium/z	 (python )c                 f    t        j                  dt        d       | j                  j                  S )zp:Returns:

        Timeout value in seconds for all http requests made to the
        Remote Connection
        z_get_timeout() in RemoteConnection is deprecated, get timeout from ClientConfig instance instead   
stacklevelwarningswarnDeprecationWarningr!   timeoutclss    ^/var/www/html/venv/lib/python3.12/site-packages/selenium/webdriver/remote/remote_connection.pyget_timeoutzRemoteConnection.get_timeout   s-     	m	

 !!)))    c                 ^    t        j                  dt        d       || j                  _        y)zyOverride the default timeout.

        :Args:
            - timeout - timeout value for http requests in seconds
        zlset_timeout() in RemoteConnection is deprecated, set timeout to ClientConfig instance in constructor insteadr&   r'   Nr)   )r/   r-   s     r0   set_timeoutzRemoteConnection.set_timeout   s)     	z	

 &-"r2   c                 p    t        j                  dt        d       | j                  j	                          y)zAReset the http request timeout to socket._GLOBAL_DEFAULT_TIMEOUT.zgreset_timeout() in RemoteConnection is deprecated, use reset_timeout() in ClientConfig instance insteadr&   r'   N)r*   r+   r,   r!   reset_timeoutr.   s    r0   r6   zRemoteConnection.reset_timeout   s-     	u	

 	((*r2   c                 f    t        j                  dt        d       | j                  j                  S )z:Returns:

        Paths of the .pem encoded certificate to verify connection to
        command executor. Defaults to certifi.where() or
        REQUESTS_CA_BUNDLE env variable if set.
        zpget_certificate_bundle_path() in RemoteConnection is deprecated, get ca_certs from ClientConfig instance insteadr&   r'   r*   r+   r,   r!   ca_certsr.   s    r0   get_certificate_bundle_pathz,RemoteConnection.get_certificate_bundle_path   s-     	~	

 !!***r2   c                 ^    t        j                  dt        d       || j                  _        y)zSet the path to the certificate bundle to verify connection to
        command executor. Can also be set to None to disable certificate
        validation.

        :Args:
            - path - path of a .pem encoded certificate chain.
        z}set_certificate_bundle_path() in RemoteConnection is deprecated, set ca_certs to ClientConfig instance in constructor insteadr&   r'   Nr8   )r/   paths     r0   set_certificate_bundle_pathz,RemoteConnection.set_certificate_bundle_path   s,     	 L	

 '+#r2   c                    dd| j                   d}|j                  rmt        j                  dd       t	        |j                   d|j
                   j                               }|j                  dd	|j                          i       |r|j                  d
di       | j                  r|j                  | j                         |S )zGet headers for remote request.

        :Args:
         - parsed_url - The parsed url
         - keep_alive (Boolean) - Is this a keep-alive connection (default: False)
        zapplication/jsonzapplication/json;charset=UTF-8)AcceptContent-Typez
User-AgentzREmbedding username and password in URL could be insecure, use ClientConfig insteadr&   r'   :AuthorizationzBasic 
Connectionz
keep-alive)

user_agentusernamer*   r+   r   passwordencodeupdatedecodeextra_headers)r/   
parsed_url
keep_aliveheadersbase64strings        r0   get_remote_connection_headersz.RemoteConnection.get_remote_connection_headers   s     )<..
 MMdqr %
(;(;'<Aj>Q>Q=R%S%Z%Z%\]LNNOvl6I6I6K5L-MNONNL,78NN3,,-r2   c                 b    t        | j                        }|j                  r|j                  ryy y )NT)r   
_proxy_urlrE   rF   )selfrK   s     r0   _identify_http_proxy_authz*RemoteConnection._identify_http_proxy_auth  s,    doo.
:#6#6 $7r2   c                     t        | j                        }|j                   d|j                   d|j                   }|j
                   d|j                   }||fS )Nz://rA   )r   rQ   schemehostnameportrE   rF   )rR   rK   proxy_without_authauths       r0   _separate_http_proxy_authz*RemoteConnection._separate_http_proxy_auth  sc    doo.
 * 1 12#j6I6I5J!JOOK\]%%&a
(;(;'<=!4''r2   c                 <   d| j                   j                  i}|j                  | j                   j                  j	                  di              | j                   j
                  r3d|d<   t        j                  t        j                  j                         n4| j                   j                  rd|d<   | j                   j                  |d<   | j                  r| j                  j                         j                  d      rdd	lm}  || j                  fi |S | j!                         r@| j#                         \  | _        | _        t        j&                  | j$                  
      |d<   t        j(                  | j                  fi |S t        j*                  di |S )Nr-   init_args_for_pool_manager	CERT_NONE	cert_reqsCERT_REQUIREDr9   sockr   )SOCKSProxyManager)proxy_basic_authproxy_headers )r!   r-   rH   r\   getignore_certificatesurllib3disable_warnings
exceptionsInsecureRequestWarningr9   rQ   lower
startswithurllib3.contrib.socksra   rS   rZ   _basic_proxy_authmake_headersProxyManagerPoolManager)rR   pool_manager_init_argsra   s      r0   _get_connection_managerz(RemoteConnection._get_connection_manager  sW   "+T-@-@-H-H!I%%::>>?[]_`	
 222=";/$$W%7%7%N%NO  ))2A";/151D1D1M1M":.??$$&11&9C(S<RSS--/:>:X:X:Z7!7:A:N:N`d`v`v:w&7''R;QRR""<%;<<r2   remote_server_addrrL   ignore_proxyrf   r\   client_configc                    |xs t        ||||      | _        | j                  j                  t        _        | j                  j
                  t        _        | j                  t        _        | j                  j                  xs t        j                  t        _        | j                  j                  xs t        j                  t        _        |rt        j                  dt        d       |st        j                  dt        d       |rt        j                  dt        d       |rt        j                  dt        d       |r$t        j                  dt        d       d | _        n| j                  j                         | _        | j                  j                  r| j                         | _        t"        | _        y )	N)rt   rL   rf   r\   zdsetting remote_server_addr in RemoteConnection() is deprecated, set in ClientConfig instance insteadr&   r'   z\setting keep_alive in RemoteConnection() is deprecated, set in ClientConfig instance insteadzesetting ignore_certificates in RemoteConnection() is deprecated, set in ClientConfig instance insteadzlsetting init_args_for_pool_manager in RemoteConnection() is deprecated, set in ClientConfig instance insteadz^setting ignore_proxy in RemoteConnection() is deprecated, set in ClientConfig instance instead)r
   r!   r-   r   _timeoutr9   	_ca_certsrJ   rD   r*   r+   r,   rQ   get_proxy_urlrL   rs   _connremote_commands	_commands)rR   rt   rL   ru   rf   r\   rv   s          r0   __init__zRemoteConnection.__init__2  sf    , 
|1! 3'A	0
 %)$7$7$?$?!%)%8%8%A%A"*.*=*=')-)<)<)J)J)lN^NlNl&&*&9&9&D&D&cHXHcHc#MMv" MMn" MMw" &MM~" MMp"
 #DO"11??ADO))557DJ(r2   c                 &    ||f| j                   |<   y)zRegister a new command.N)r}   )rR   namemethodurls       r0   add_commandzRemoteConnection.add_commandu  s     &}tr2   r   c                 8    | j                   j                  |      S )z Retrieve a command if it exists.)r}   re   )rR   r   s     r0   get_commandzRemoteConnection.get_commandy  s    ~~!!$''r2   c                 z   | j                   j                  |      xs | j                  j                  |      }|
J d|        |d   }t        j                  |      j                  |      }|j                  d      D ch c]  }|j                  d      s|dd  }}t        |t              r|r
|D ]  }||=  t        j                  |      }| j                  j                   | }	| j                  |      }
t        j!                  d|d   |	t#        |
             | j%                  |d   |	|      S c c}w )	am  Send a command to the remote server.

        Any path substitutions required for the URL mapped to the command should be
        included in the command parameters.

        :Args:
         - command - A string specifying the command to execute.
         - params - A dictionary of named parameters to send with the command as
           its JSON payload.
        NzUnrecognised command r   /$z%s %s %sr   )body)r}   re   extra_commandsstringTemplate
substitutesplitrl   
isinstancedictr	   	dump_jsonr!   rt   _trim_large_entriesLOGGERdebugstr_request)rR   commandparamscommand_infopath_stringr<   wordsubstitute_paramsdatar   trimmeds              r0   executezRemoteConnection.execute}  s/    ~~))'2Vd6I6I6M6Mg6V'J+@	)JJ'"1o{+66v>2=2C2CC2Ha$DOO\_L`T!"Xaafd#(9) !4L!v&$$778?**62Za#s7|D}}\!_c}== bs   D8D8c                    t        j                  |      }| j                  || j                  j                        }| j                  j                         }|r|j                  |       |r|dvrd}| j                  j                  rA| j                  j                  ||||| j                  j                        }|j                  }nQ| j                         }	|	5 }
|
j                  ||||| j                  j                        }ddd       j                  }|j                  j                  d      }t        j                  d|j                  ||j                          	 d|cxk  rdk  rTn nQ| j#                  d|j                   j%                  d	d            t        j                  d
       |j'                          S d|cxk  rdk  rwn nt|dk(  r*|ddt        j                  d
       |j'                          S ||st)        |      n|j+                         dt        j                  d
       |j'                          S g }|j                   j%                  dd      r+|j                   j%                  dd      j-                  d      }t/        |D cg c]  }|j1                  d       c}      sT	 t3        j4                  |j+                               }d|vrd|d<   |t        j                  d
       |j'                          S d|d}|t        j                  d
       |j'                          S # 1 sw Y   0xY wc c}w # t6        $ rj d|cxk  rdk  rn nt8        j:                  }nt8        j<                  }||j+                         dcY t        j                  d
       |j'                          S w xY w# t        j                  d
       |j'                          w xY w)aq  Send an HTTP request to the remote server.

        :Args:
         - method - A string for the HTTP method to send the request with.
         - url - A string for the URL to send the request to.
         - body - A string for request body. Ignored unless method is POST or PUT.

        :Returns:
          A dictionary with the server's parsed JSON response.
        )r   PUTN)r   rM   r-   zUTF-8z1Remote response: status=%s | data=%s | headers=%si,  i0  r   locationzFinished Requesti  i  i  zAuthorization Required)statusvaluer@   ;z	image/png   r   r   )r   r   rO   r!   rL   get_auth_headerrH   r{   requestr-   r   rs   r   rI   r   r   rM   r   re   closer   stripr   anyrl   r	   	load_json
ValueErrorr   SUCCESSUNKNOWN_ERROR)rR   r   r   r   rK   rM   auth_headerresponse
statuscodeconnhttpr   content_typexr   s                  r0   r   zRemoteConnection._request  s9    ^^C(
44ZATATA_A_`))99;NN;'F/1D))zz))&#D'[_[n[n[v[v)wH!J//1D v<<$Y]YlYlYtYt<uv!J}}##G,H(//[_aiaqaqr	j&3&}}UH,<,<,@,@T,RS4 LL+,NN5 Z&3&$&0;ST. LL+,NN/ #-ds:X\XbXbXde, LL+,NN- L##ND9'//33NDIOOPST<Ha[1HIE ??4::<8D $&$(DM LL+,NN	  $/DLL+,NNEv v I " EZ-#-!*!2!2!*!8!8&,tzz|DD LL+,NN!E LL+,NNsh   +L3!9N;  N; =N; AN; M ,N; 4#M 
N; N; 3L= N; AN8N; 7N88N; ;'O"c                 R    t        | d      r| j                  j                          yy)z<Clean up resources when finished with the remote_connection.r{   N)hasattrr{   clear)rR   s    r0   r   zRemoteConnection.close  s!    4!JJ "r2   c                     i }|j                         D ]Z  \  }}t        |t              r| j                  ||      ||<   ,t        |t              rt        |      |kD  r|d| dz   ||<   V|||<   \ |S )a  Truncate string values in a dictionary if they exceed max_length.

        :param dict: Dictionary with potentially large values
        :param max_length: Maximum allowed length of string values
        :return: Dictionary with truncated string values
        Nz...)itemsr   r   r   r   len)rR   
input_dict
max_lengthoutput_dictionarykeyr   s         r0   r   z$RemoteConnection._trim_large_entries  s     $**, 	/JC%&)-)A)A%)T!#&E3'CJ,C).{
);e)C!#&).!#&	/ ! r2   )F)NTFFNN)N)d   ).__name__
__module____qualname____doc__browser_nameossocketcertifigetenvfloatr   getdefaulttimeoutrx   environwherery   r!   r
   __annotations__platformsystemrk   rJ   r   rD   classmethodr1   r4   r6   r:   r=   rO   rS   rZ   rs   r   boolr   r~   r   r   r   r   r   r   r   rd   r2   r0   r   r      s    L 99-.: 	bii0#f6N6N6P2QRS%%' 
 4H2::3U		./[b[h[h[jI#'NL'X__$$&F M[M6(!<J* * - - + + + + + +  :
(=6 -1%)',.35904?)$SM?) TN?) tn	?)
 &d^?) %-TN?)  -?)B N-( (>2<|
!r2   r   )uloggingr   r   r*   base64r   typingr   urllibr   urllib.parser   rg   seleniumr    r	   rv   r
   r   r   errorhandlerr   	getLoggerr   r   NEW_SESSIONQUITW3C_GET_CURRENT_WINDOW_HANDLEW3C_GET_WINDOW_HANDLESr   
GO_FORWARDGO_BACKREFRESHW3C_EXECUTE_SCRIPTW3C_EXECUTE_SCRIPT_ASYNCGET_CURRENT_URL	GET_TITLEGET_PAGE_SOURCE
SCREENSHOTELEMENT_SCREENSHOTFIND_ELEMENTFIND_ELEMENTSW3C_GET_ACTIVE_ELEMENTFIND_CHILD_ELEMENTFIND_CHILD_ELEMENTSCLICK_ELEMENTCLEAR_ELEMENTGET_ELEMENT_TEXTSEND_KEYS_TO_ELEMENTGET_ELEMENT_TAG_NAMEIS_ELEMENT_SELECTEDIS_ELEMENT_ENABLEDGET_ELEMENT_RECTGET_ELEMENT_ATTRIBUTEGET_ELEMENT_PROPERTYGET_ELEMENT_ARIA_ROLEGET_ELEMENT_ARIA_LABELGET_SHADOW_ROOTFIND_ELEMENT_FROM_SHADOW_ROOTFIND_ELEMENTS_FROM_SHADOW_ROOTGET_ALL_COOKIES
ADD_COOKIE
GET_COOKIEDELETE_ALL_COOKIESDELETE_COOKIESWITCH_TO_FRAMESWITCH_TO_PARENT_FRAMESWITCH_TO_WINDOW
NEW_WINDOWCLOSE!GET_ELEMENT_VALUE_OF_CSS_PROPERTYEXECUTE_ASYNC_SCRIPTSET_TIMEOUTSGET_TIMEOUTSW3C_DISMISS_ALERTW3C_ACCEPT_ALERTW3C_SET_ALERT_VALUEW3C_GET_ALERT_TEXTW3C_ACTIONSW3C_CLEAR_ACTIONSSET_WINDOW_RECTGET_WINDOW_RECTW3C_MAXIMIZE_WINDOWSET_SCREEN_ORIENTATIONGET_SCREEN_ORIENTATIONGET_NETWORK_CONNECTIONSET_NETWORK_CONNECTIONGET_LOGGET_AVAILABLE_LOG_TYPESCURRENT_CONTEXT_HANDLECONTEXT_HANDLESSWITCH_TO_CONTEXTFULLSCREEN_WINDOWMINIMIZE_WINDOW
PRINT_PAGEADD_VIRTUAL_AUTHENTICATORREMOVE_VIRTUAL_AUTHENTICATORADD_CREDENTIALGET_CREDENTIALSREMOVE_CREDENTIALREMOVE_ALL_CREDENTIALSSET_USER_VERIFIEDUPLOAD_FILEGET_DOWNLOADABLE_FILESDOWNLOAD_FILEDELETE_DOWNLOADABLE_FILESGET_FEDCM_TITLEGET_FEDCM_DIALOG_TYPEGET_FEDCM_ACCOUNT_LISTCLICK_FEDCM_DIALOG_BUTTONCANCEL_FEDCM_DIALOGSELECT_FEDCM_ACCOUNTSET_FEDCM_DELAYRESET_FEDCM_COOLDOWNr|   r   rd   r2   r0   <module>r5     s  $        !     '  #			8	$d-dLL3d ))+Pd ""$Q	d
 KK4d ?d OO9d OO<d  Ld $$&Sd ?d ;d Bd Ad  Ud  A!d" C#d$ ""$Q%d&  S'd( !U)d* L+d, L-d. M/d0   "S1d2   "Q3d4 !T5d6  R7d8 M9d: !!#];d<   "[=d> !!#Z?d@ ""$\AdB NCdD ))+cEdF **,eGdH BIdJ >KdL CMdN  HOdP IQdR BSdT ""$PUdV DWdX BYdZ MM;[d\ --/k]d^   "O_d` Badb Acdd Ledf Jgdh !Kidj  Ikdl @mdn Hodp Hqdr Gsdt !Pudv ""$Owdx ""$Nydz ""$U{d| ""$V}d~ OO;d@ ##%PAdB ""$JCdD DEdF FGdH PIdJ LKdL =MdN %%']OdP (( +QdX nYdZ o[d\   ]dd "" %edl imdn @odp ""$Kqdr Csdt %%'Qudx Jydz !!#U{d| ""$T}d~ %%'^d@ !S  "UR  "UGdN\! \!r2   