o
    衡i                     @   s   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 G d	d
 d
eZdS )    N)contextmanager)BytesIO)DriverFinder)LocalWebDriver)Options)FirefoxRemoteConnection)Servicec                	       s   e Zd ZdZdZdZ			ddedB dedB ded	df fd
dZ	dddZ
edd Zdd	efddZdddZd	efddZd	efddZd	efddZd	efddZ  ZS ) 	WebDriverz=Controls the GeckoDriver and allows you to drive the browser.chromecontentNToptionsservice
keep_alivereturnc                    s   |r|nt  | _|r|nt | _t| j| j}| r%| | j_d| j_| j p-|	 | j_
| j  t| jj|| jjd}zt j|| jd W dS  tyX   |    w )a^  Create a new instance of the Firefox driver, start the service, and create new instance.

        Args:
            options: Instance of Options.
            service: Service object for handling the browser driver if you need to pass extra details.
            keep_alive: Whether to configure FirefoxRemoteConnection to use HTTP keep-alive.
        N)remote_server_addrr   ignore_proxy)command_executorr   )r   r   r   r   r   get_browser_pathbinary_locationbrowser_versionenv_pathget_driver_pathpathstartr   service_url_ignore_local_proxysuper__init__	Exceptionquit)selfr   r   r   finderexecutor	__class__ u/var/www/html/asbeauty/laura_geller_scraping/env/lib/python3.10/site-packages/selenium/webdriver/firefox/webdriver.pyr   &   s&   
zWebDriver.__init__c                 C      |  dd|i dS )zSets the context that Selenium commands are running in.

        Args:
            context: Context to set, should be one of CONTEXT_CHROME or CONTEXT_CONTENT.
        SET_CONTEXTcontextNexecute)r    r)   r%   r%   r&   set_contextJ   s   zWebDriver.set_contextc              	   c   s@    |  dd}| | zdV  W | | dS | | w )a  Set 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.

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

        Example:
            with selenium.context(selenium.CONTEXT_CHROME):
                # chrome scope
                ... do stuff ...
        GET_CONTEXTvalueN)r+   popr,   )r    r)   initial_contextr%   r%   r&   r)   R   s   
zWebDriver.contextFc              	   C   s  t j|r[t }t j|}t|d }tj|dtjdd)}t 	|D ]\}}}|D ]}	t j
||	}
||
|
|d  q,q%W d   n1 sKw   Y  t| d}nt|d}t| d}W d   n1 suw   Y  ||d}| d	|d
 S )a  Installs Firefox addon.

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

        Args:
            path: Absolute path to the addon that will be installed.
            temporary: Allows you to load browser extensions temporarily during a session.

        Returns:
            Identifier of installed addon.

        Example:
            driver.install_addon("/path/to/firebug.xpi")
           wF)strict_timestampsNzUTF-8rb)addon	temporaryINSTALL_ADDONr.   )osr   isdirr   normpathlenzipfileZipFileZIP_DEFLATEDwalkjoinwritebase64	b64encodegetvaluedecodeopenreadr+   )r    r   r6   fp	path_rootzippedbase_filesfylefilenamer5   filepayloadr%   r%   r&   install_addoni   s$   
zWebDriver.install_addonc                 C   r'   )zUninstalls Firefox addon using its identifier.

        Args:
            identifier: The addon identifier to uninstall.

        Example:
            driver.uninstall_addon("addon@foo.com")
        UNINSTALL_ADDONidNr*   )r    
identifierr%   r%   r&   uninstall_addon      	zWebDriver.uninstall_addonc                 C   s   |  dstdt |  }z1z$t|d}|| W d   n1 s(w   Y  W W ~dS W W ~dS  tyB   Y W ~dS w ~w )a  Save a full document screenshot of the current window to a PNG image file.

        Args:
            filename: The full path you wish to save your screenshot to. This
                should end with a `.png` extension.

        Returns:
            False if there is any IOError, else returns True. Use full paths in your filename.

        Example:
            driver.get_full_page_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wbNFT)	lowerendswithwarningswarnUserWarningget_full_page_screenshot_as_pngrF   rA   OSError)r    rO   pngfr%   r%   r&    get_full_page_screenshot_as_file   s(    z*WebDriver.get_full_page_screenshot_as_filec                 C   s
   |  |S )a  Save a full document screenshot of the current window to a PNG image file.

        Args:
            filename: The full path you wish to save your screenshot to. This
                should end with a `.png` extension.

        Returns:
            False if there is any IOError, else returns True. Use full paths in your filename.

        Example:
            driver.save_full_page_screenshot("/Screenshots/foo.png")
        )rb   )r    rO   r%   r%   r&   save_full_page_screenshot   s   
z#WebDriver.save_full_page_screenshotc                 C   s   t |  dS )zGet the full document screenshot of the current window as binary data.

        Returns:
            Binary data of the screenshot.

        Example:
            driver.get_full_page_screenshot_as_png()
        ascii)rB   	b64decode"get_full_page_screenshot_as_base64encoder    r%   r%   r&   r^      rW   z)WebDriver.get_full_page_screenshot_as_pngc                 C   s   |  dd S )zGet the full document screenshot of the current window as a base64-encoded string.

        Returns:
            Base64 encoded string of the screenshot.

        Example:
            driver.get_full_page_screenshot_as_base64()
        FULL_PAGE_SCREENSHOTr.   r*   rh   r%   r%   r&   rf      s   	z,WebDriver.get_full_page_screenshot_as_base64)NNT)r   N)F)__name__
__module____qualname____doc__CONTEXT_CHROMECONTEXT_CONTENTr   r   boolr   r,   r   r)   strrR   rV   rb   rc   bytesr^   rf   __classcell__r%   r%   r#   r&   r	       s2    
$

#r	   )rB   r8   r[   r<   
contextlibr   ior   'selenium.webdriver.common.driver_finderr   #selenium.webdriver.common.webdriverr   "selenium.webdriver.firefox.optionsr   ,selenium.webdriver.firefox.remote_connectionr   "selenium.webdriver.firefox.servicer   r	   r%   r%   r%   r&   <module>   s   