B
     h)                 @   s   d dl Z ye W n ek
r(   eZY nX 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 G dd deZdS )    N)contextmanager)DesiredCapabilities)	WebDriver   )ExtensionConnection)FirefoxBinary)FirefoxProfile)Options)FirefoxRemoteConnection)Service)FirefoxWebElementc               @   sf   e Zd ZejdkZdZdZeZ	dd	d
Z
dd Zedd Zdd Zedd ZdddZdd ZdS )r   darwinZchromecontentN   geckodrivergeckodriver.logTc             C   s  |rt jdtdd |}|	r0t jdtdd |	}d| _d| _d| _|dkrR|rR|}|dkrdtj }|dkrrt	 }t
|}|dr|d | _|dk	r|jdk	r|j| _|jdk	r|j| _|dk	rt|trt|}|| _||_|dk	rt|trt|}|| _||_|drh|d t||
|d| _| j  ||  t| jjd	}tj| ||d
d nt| jdkr|t | _| jdkrt | _| jo| jj| j_|dk	r|| td| j| j|}tj| |||d d| _dS )a  Starts a new local session of Firefox.

        Based on the combination and specificity of the various keyword
        arguments, a capabilities dictionary will be constructed that
        is passed to the remote end.

        The keyword arguments given to this constructor are helpers to
        more easily allow Firefox WebDriver sessions to be customised
        with different options.  They are mapped on to a capabilities
        dictionary that is passed on to the remote end.

        As some of the options, such as `firefox_profile` and
        `options.profile` are mutually exclusive, precedence is
        given from how specific the setting is.  `capabilities` is the
        least specific keyword argument, followed by `options`,
        followed by `firefox_binary` and `firefox_profile`.

        In practice this means that if `firefox_profile` and
        `options.profile` are both set, the selected profile
        instance will always come from the most specific variable.
        In this case that would be `firefox_profile`.  This will result in
        `options.profile` to be ignored because it is considered
        a less specific setting than the top-level `firefox_profile`
        keyword argument.  Similarily, if you had specified a
        `capabilities["moz:firefoxOptions"]["profile"]` Base64 string,
        this would rank below `options.profile`.

        :param firefox_profile: Instance of ``FirefoxProfile`` object
            or a string.  If undefined, a fresh profile will be created
            in a temporary location on the system.
        :param firefox_binary: Instance of ``FirefoxBinary`` or full
            path to the Firefox binary.  If undefined, the system default
            Firefox installation will  be used.
        :param timeout: Time to wait for Firefox to launch when using
            the extension connection.
        :param capabilities: Dictionary of desired capabilities.
        :param proxy: The proxy settings to us when communicating with
            Firefox via the extension connection.
        :param executable_path: Full path to override which geckodriver
            binary to use for Firefox 47.0.1 and greater, which
            defaults to picking up the binary from the system path.
        :param options: Instance of ``options.Options``.
        :param service_log_path: Where to log information from the driver.
        :param firefox_options: Deprecated argument for options
        :param service_args: List of args to pass to the driver service
        :param desired_capabilities: alias of capabilities. In future
            versions of this library, this will replace 'capabilities'.
            This will make the signature consistent with RemoteWebDriver.
        :param log_path: Deprecated argument for service_log_path
        :param keep_alive: Whether to configure remote_connection.RemoteConnection to use
             HTTP keep-alive.
        z(use service_log_path instead of log_path   )
stacklevelz&use options instead of firefox_optionsNbinaryZ
marionette)service_argslog_path)Zremote_server_addrT)command_executordesired_capabilities
keep_alivez	127.0.0.1F)warningswarnDeprecationWarningr   profileservicer   ZFIREFOXcopyr	   dictget
isinstance
basestringr   r   popr   startupdateto_capabilitiesr
   service_urlRemoteWebDriver__init__NATIVE_EVENTS_ALLOWEDZnative_events_enabledZadd_to_capabilitiesr   Z
_is_remote)selffirefox_profilefirefox_binarytimeoutcapabilitiesproxyexecutable_pathoptionsZservice_log_pathZfirefox_optionsr   r   r   r   Zexecutor r4   aC:\Users\sanjo\AppData\Local\Qlobot\Launcher\ext_packages\selenium\webdriver\firefox\webdriver.pyr*   2   s    :
















zWebDriver.__init__c          
   C   s   yt |  W n tk
r"   Y nX | jr6| j  n
| j  | jdk	ry,t	
| jj | jjdk	rtt	
| jj W n. tk
r } ztt| W dd}~X Y nX dS )z3Quits the driver and close every associated window.N)r)   quit	ExceptionZw3cr   stopr   killr   shutilrmtreepathZ
tempfolderprintstr)r,   er4   r4   r5   r6      s    

zWebDriver.quitc             C   s   | j S )N)r   )r,   r4   r4   r5   r-      s    zWebDriver.firefox_profilec             C   s   |  dd|i d S )NZSET_CONTEXTcontext)execute)r,   r@   r4   r4   r5   set_context   s    zWebDriver.set_contextc          	   c   s6   |  dd}| | z
dV  W d| | X dS )a  Sets the context that Selenium commands are running in using
        a `with` statement. The state of the context on the server is
        saved before entering the block, and restored upon exiting it.

        :param context: Context, may be one of the class properties
            `CONTEXT_CHROME` or `CONTEXT_CONTENT`.

        Usage example::

            with selenium.context(selenium.CONTEXT_CHROME):
                # chrome scope
                ... do stuff ...
        ZGET_CONTEXTvalueN)rA   r$   rB   )r,   r@   Zinitial_contextr4   r4   r5   r@      s
    

zWebDriver.contextc             C   s(   d|i}|dk	r||d< |  d|d S )a*  
        Installs Firefox addon.

        Returns identifier of installed addon. This identifier can later
        be used to uninstall addon.

        :param path: Absolute path to the addon that will be installed.

        :Usage:
            driver.install_addon('/path/to/firebug.xpi')
        r<   N	temporaryZINSTALL_ADDONrC   )rA   )r,   r<   rD   payloadr4   r4   r5   install_addon   s    zWebDriver.install_addonc             C   s   |  dd|i dS )z
        Uninstalls Firefox addon using its identifier.

        :Usage:
            driver.uninstall_addon('addon@foo.com')
        ZUNINSTALL_ADDONidN)rA   )r,   Z
identifierr4   r4   r5   uninstall_addon  s    zWebDriver.uninstall_addon)NNr   NNr   Nr   NNNNT)N)__name__
__module____qualname__sysplatformr+   ZCONTEXT_CHROMEZCONTEXT_CONTENTr   Z_web_element_clsr*   r6   propertyr-   rB   r   r@   rF   rH   r4   r4   r4   r5   r   (   s"   
     
 
r   )r   r#   	NameErrorr>   r:   rL   
contextlibr   Z.selenium.webdriver.common.desired_capabilitiesr   Z#selenium.webdriver.remote.webdriverr   r)   Zextension_connectionr   r.   r   r-   r   r3   r	   Zremote_connectionr
   r   r   Z
webelementr   r4   r4   r4   r5   <module>   s"   
