o
    ѷ6i1                     @   s   d dl Z d dlmZmZ d dlmZ d dlmZ d dlm	Z	 G dd de
eZG dd	 d	ZG d
d dZG dd dZG dd dZG dd dZG dd dedZG dd deZdS )    N)ABCMetaabstractmethod)Enum)InvalidArgumentException)Proxyc                   @   s   e Zd ZdZdZdZdZdS )PageLoadStrategya  Enum of possible page load strategies.

    Selenium support following strategies:
        * normal (default) - waits for all resources to download
        * eager - DOM access is ready, but other resources like images may still be loading
        * none - does not block `WebDriver` at all

    Docs: https://www.selenium.dev/documentation/webdriver/drivers/options/#pageloadstrategy.
    normaleagernoneN)__name__
__module____qualname____doc__r   r	   r
    r   r   f/var/www/hoanhtaovolam_webdjango/env/lib/python3.10/site-packages/selenium/webdriver/common/options.pyr      s
    
r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )_BaseOptionsDescriptorc                 C   
   || _ d S Nnameselfr   r   r   r   __init__+      
z_BaseOptionsDescriptor.__init__c                 C   sz   | j dkr|jd}|du pt|tS | j dkr)|j| j }t|ts'd S |S | j dv r6|j| j dS |j| j S )N
enableBidiwebSocketUrlT)acceptInsecureCertsstrictFileInteractabilitysetWindowRectse:downloadsEnabledF)r   _capsget
isinstancestr)r   objclsvaluer   r   r   __get__.   s   


z_BaseOptionsDescriptor.__get__c                 C   s,   | j dkr|d| d S || j | d S )Nr   r   )r   set_capabilityr   r$   r&   r   r   r   __set__;   s   
z_BaseOptionsDescriptor.__set__N)r   r   r   r   r'   r*   r   r   r   r   r   *   s    r   c                   @   (   e Zd ZdZdd Zdd Zdd ZdS )	_PageLoadStrategyDescriptorzDetermines the point at which a navigation command is returned.

    See:
      - https://w3c.github.io/webdriver/#dfn-table-of-page-load-strategies.

    Args:
        strategy: the strategy corresponding to a document readiness state
    c                 C   r   r   r   r   r   r   r   r   L   r   z$_PageLoadStrategyDescriptor.__init__c                 C      |j | jS r   r    r!   r   r   r$   r%   r   r   r   r'   O      z#_PageLoadStrategyDescriptor.__get__c                 C   "   |dv r| | j| d S td)N)r   r	   r
   z>Strategy can only be one of the following: normal, eager, noner(   r   
ValueErrorr)   r   r   r   r*   R   s   z#_PageLoadStrategyDescriptor.__set__Nr   r   r   r   r   r'   r*   r   r   r   r   r,   B   s
    	r,   c                   @   r+   )	"_UnHandledPromptBehaviorDescriptora{  How the driver should respond when an alert is present and the command sent is not handling the alert.

    See:
      - https://w3c.github.io/webdriver/#dfn-table-of-page-load-strategies:

    Args:
        behavior: behavior to use when an alert is encountered

    Returns:
        Values for implicit timeout, pageLoad timeout and script timeout if set (in milliseconds)
    c                 C   r   r   r   r   r   r   r   r   f   r   z+_UnHandledPromptBehaviorDescriptor.__init__c                 C   r-   r   r.   r/   r   r   r   r'   i   r0   z*_UnHandledPromptBehaviorDescriptor.__get__c                 C   r1   )N)dismissacceptzdismiss and notifyzaccept and notifyignoreziBehavior can only be one of the following: dismiss, accept, dismiss and notify, accept and notify, ignorer2   r)   r   r   r   r*   l   s
   z*_UnHandledPromptBehaviorDescriptor.__set__Nr4   r   r   r   r   r5   Y   
    r5   c                   @   r+   )	_TimeoutsDescriptorag  How long the driver should wait for actions to complete before returning an error.

    See:
      - https://w3c.github.io/webdriver/#timeouts

    Args:
        timeouts: values in milliseconds for implicit wait, page load and script timeout

    Returns:
        Values for implicit timeout, pageLoad timeout and script timeout if set (in milliseconds)
    c                 C   r   r   r   r   r   r   r   r      r   z_TimeoutsDescriptor.__init__c                 C   r-   r   r.   r/   r   r   r   r'      r0   z_TimeoutsDescriptor.__get__c                 C   s0   t dd | D r|| j| d S td)Nc                 s   s    | ]}|d v V  qdS ))implicitpageLoadscriptNr   ).0xr   r   r   	<genexpr>   s    z._TimeoutsDescriptor.__set__.<locals>.<genexpr>zITimeout keys can only be one of the following: implicit, pageLoad, script)allkeysr(   r   r3   r)   r   r   r   r*      s   z_TimeoutsDescriptor.__set__Nr4   r   r   r   r   r:   v   r9   r:   c                   @   r+   )	_ProxyDescriptorz^Descriptor for proxy property access.

    Returns:
        Proxy if set, otherwise None.
    c                 C   r   r   r   r   r   r   r   r      r   z_ProxyDescriptor.__init__c                 C   s   |j S r   )_proxyr/   r   r   r   r'         z_ProxyDescriptor.__get__c                 C   s,   t |ts	td||_| |j| j< d S )Nz$Only Proxy objects can be passed in.)r"   r   r   rD   to_capabilitiesr    r   r)   r   r   r   r*      s   
z_ProxyDescriptor.__set__Nr4   r   r   r   r   rC      s
    rC   c                	       s  e Zd ZdZedZ	 edZ	 edZ	 edZ	 edZ		 edZ
	 edZ	 ed	Z	 ed
Z	 edZ	 edZ	 edZ	 d! fddZedd Zd!ddZ			d"dedB dedB dedB ddfddZedd Zeedd Zd!dd Z  ZS )#BaseOptionsz*Base class for individual browser options.browserVersionplatformNamer   r   r   r   pageLoadStrategyunhandledPromptBehaviortimeoutsproxyr   r   returnNc                    s6   t    | j| _d | _| dtj d | _d| _	d S )NrJ   F)
superr   default_capabilitiesr    rD   r(   r   r   mobile_options_ignore_local_proxyr   	__class__r   r   r   O  s   

zBaseOptions.__init__c                 C      | j S r   r    rS   r   r   r   capabilitiesW  s   zBaseOptions.capabilitiesc                 C   s   || j |< dS )zSets a capability.NrW   )r   r   r&   r   r   r   r(   [  s   zBaseOptions.set_capabilityandroid_packageandroid_activitydevice_serialc                 C   s:   |st dd|i| _|r|| jd< |r|| jd< dS dS )a	  Enables mobile browser use for browsers that support it.

        Args:
            android_package: The name of the android package to start
            android_activity: The name of the android activity
            device_serial: The device serial number
        z!android_package must be passed inandroidPackageandroidActivityandroidDeviceSerialN)AttributeErrorrQ   )r   rY   rZ   r[   r   r   r   enable_mobile_  s   

zBaseOptions.enable_mobilec                 C      dS )z-Convert options into capabilities dictionary.Nr   rS   r   r   r   rF   t      zBaseOptions.to_capabilitiesc                 C   ra   )z6Return minimal capabilities necessary as a dictionary.Nr   rS   r   r   r   rP   x  rb   z BaseOptions.default_capabilitiesc                 C   s
   d| _ dS )z8Ignore HTTP_PROXY and HTTPS_PROXY environment variables.TN)rR   rS   r   r   r   (ignore_local_proxy_environment_variables}  s   
z4BaseOptions.ignore_local_proxy_environment_variablesrN   N)NNN) r   r   r   r   r   browser_versionplatform_nameaccept_insecure_certsstrict_file_interactabilityset_window_rectenable_bidir,   page_load_strategyr5   unhandled_prompt_behaviorr:   rL   rC   rM   enable_downloadsweb_socket_urlr   propertyrX   r(   r#   r`   r   rF   rP   rc   __classcell__r   r   rT   r   rG      s`    



rG   )	metaclassc                       sf   e Zd ZdZdZd fddZedd Zd	eddfd
dZ	d fddZ
dd Zedd Z  ZS )
ArgOptionsz Binary Location Must be a Stringzfedcm:accountsrN   Nc                    s   t    g | _d S r   )rO   r   
_argumentsrS   rT   r   r   r     s   

zArgOptions.__init__c                 C   rV   )z3Returns a list of arguments needed for the browser.)rs   rS   r   r   r   	arguments  s   zArgOptions.argumentsargumentc                 C   s   |r
| j | dS td)z^Adds an argument to the list.

        Args:
            argument: Sets the arguments
        zargument can not be nullN)rs   appendr3   )r   ru   r   r   r   add_argument  s   zArgOptions.add_argumentc                    s   t jdtdd t   dS )zIgnore HTTP_PROXY and HTTPS_PROXY environment variables.

        This method is deprecated; use a Proxy instance with ProxyType.DIRECT instead.
        a  using ignore_local_proxy_environment_variables in Options has been deprecated, instead, create a Proxy instance with ProxyType.DIRECT to ignore proxy settings, pass the proxy instance into a ClientConfig constructor, pass the client config instance into the Webdriver constructor   )
stacklevelN)warningswarnDeprecationWarningrO   rc   rS   rT   r   r   rc     s   	z3ArgOptions.ignore_local_proxy_environment_variablesc                 C   rV   r   rW   rS   r   r   r   rF     rE   zArgOptions.to_capabilitiesc                 C   s   i S r   r   rS   r   r   r   rP     s   zArgOptions.default_capabilitiesrd   )r   r   r   BINARY_LOCATION_ERRORFEDCM_CAPABILITYr   ro   rt   r#   rw   rc   rF   rP   rp   r   r   rT   r   rr     s    
rr   )rz   abcr   r   enumr   selenium.common.exceptionsr   selenium.webdriver.common.proxyr   r#   r   r   r,   r5   r:   rC   rG   rr   r   r   r   r   <module>   s    _