B
     h                 @   sL   d dl Z d dlmZ ddlmZ ddlmZ ddlm	Z	 G dd deZdS )	    N)	WebDriver   )ChromeRemoteConnection)Service)Optionsc               @   sJ   e Zd ZdZdddZdd	 Zd
d Zdd Zdd Zdd Z	dd Z
dS )r   z
    Controls the ChromeDriver and allows you to drive the browser.

    You will need to download the ChromeDriver executable from
    http://chromedriver.storage.googleapis.com/index.html
    chromedriverr   NTc	       	      C   s   |rt jdtdd |}|dkr6|dkrV|   }n |dkrH| }n||  t||||d| _| j  y t	j
| t| jj|d|d W n tk
r   |    Y nX d| _dS )	ac  
        Creates a new instance of the chrome driver.

        Starts the service and then creates new instance of chrome driver.

        :Args:
         - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
         - port - port you would like the service to run, if left as 0, a free port will be found.
         - options - this takes an instance of ChromeOptions
         - service_args - List of args to pass to the driver service
         - desired_capabilities - Dictionary object with non-browser specific
           capabilities only, such as "proxy" or "loggingPref".
         - service_log_path - Where to log information from the driver.
         - chrome_options - Deprecated argument for options
         - keep_alive - Whether to configure ChromeRemoteConnection to use HTTP keep-alive.
        z%use options instead of chrome_options   )
stacklevelN)portservice_argslog_path)remote_server_addr
keep_alive)command_executordesired_capabilitiesF)warningswarnDeprecationWarningcreate_optionsto_capabilitiesupdater   servicestartRemoteWebDriver__init__r   service_url	Exceptionquit
_is_remote)	selfexecutable_pathr
   optionsr   r   service_log_pathchrome_optionsr    r$   `C:\Users\sanjo\AppData\Local\Qlobot\Launcher\ext_packages\selenium\webdriver\chrome\webdriver.pyr   !   s6    



zWebDriver.__init__c             C   s   |  dd|iS )z$Launches Chrome app specified by id.Z	launchAppid)execute)r   r&   r$   r$   r%   
launch_appW   s    zWebDriver.launch_appc             C   s   |  dd S )z
        Gets Chrome network emulation settings.

        :Returns:
            A dict. For example:

            {'latency': 4, 'download_throughput': 2, 'upload_throughput': 2,
            'offline': False}

        ZgetNetworkConditionsvalue)r'   )r   r$   r$   r%   get_network_conditions[   s    z WebDriver.get_network_conditionsc             K   s   |  dd|i dS )a  
        Sets Chrome network emulation settings.

        :Args:
         - network_conditions: A dict with conditions specification.

        :Usage:
            driver.set_network_conditions(
                offline=False,
                latency=5,  # additional latency (ms)
                download_throughput=500 * 1024,  # maximal throughput
                upload_throughput=500 * 1024)  # maximal throughput

            Note: 'throughput' can be used to set both (for download and upload).
        ZsetNetworkConditionsnetwork_conditionsN)r'   )r   r+   r$   r$   r%   set_network_conditionsh   s    z WebDriver.set_network_conditionsc             C   s   |  d||dd S )a  
        Execute Chrome Devtools Protocol command and get returned result

        The command and command args should follow chrome devtools protocol domains/commands, refer to link
        https://chromedevtools.github.io/devtools-protocol/

        :Args:
         - cmd: A str, command name
         - cmd_args: A dict, command args. empty dict {} if there is no command args

        :Usage:
            driver.execute_cdp_cmd('Network.getResponseBody', {'requestId': requestId})

        :Returns:
            A dict, empty dict {} if there is no result to return.
            For example to getResponseBody:

            {'base64Encoded': False, 'body': 'response body string'}

        ZexecuteCdpCommand)cmdparamsr)   )r'   )r   r-   Zcmd_argsr$   r$   r%   execute_cdp_cmd|   s    zWebDriver.execute_cdp_cmdc             C   s:   z(yt |  W n tk
r$   Y nX W d| j  X dS )z
        Closes the browser and shuts down the ChromeDriver executable
        that is started when starting the ChromeDriver
        N)r   r   r   r   stop)r   r$   r$   r%   r      s
    
zWebDriver.quitc             C   s   t  S )N)r   )r   r$   r$   r%   r      s    zWebDriver.create_options)r   r   NNNNNT)__name__
__module____qualname____doc__r   r(   r*   r,   r/   r   r   r$   r$   r$   r%   r      s      
3r   )
r   #selenium.webdriver.remote.webdriverr   r   remote_connectionr   r   r   r!   r   r$   r$   r$   r%   <module>   s
   