
    g                         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e          ZdS )    N)contextmanager)BytesIO)DriverFinder)	WebDriver   )Options)FirefoxRemoteConnection)Servicec            	            e Zd ZdZdZdZ	 	 	 ddededed	df fd
Z	d fdZ
ddZed             Zdd	efdZddZd	efdZd	efdZd	efdZd	efdZ xZS )r   z=Controls the GeckoDriver and allows you to drive the browser.chromecontentNToptionsservice
keep_alivereturnc                 l   |r|nt                      | _        |r|nt                      }t          | j        |          }|                                r |                                |_        d|_        | j                                        p|                                | j        _	        | j        
                                 t          | j        j        ||j                  }	 t                                          ||           n## t           $ r |                                   w xY wd| _        dS )a  Creates a new instance of the Firefox driver. Starts the service and
        then creates new instance of Firefox driver.

        :Args:
         - options - Instance of ``options.Options``.
         - service - (Optional) service instance for managing the starting and stopping of the driver.
         - keep_alive - Whether to configure remote_connection.RemoteConnection to use HTTP keep-alive.
        N)remote_server_addrr   ignore_proxy)command_executorr   F)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
_is_remote)selfr   r   r   finderexecutor	__class__s         p/var/www/html/nodeJS/PythonScripts/venv3.11/lib/python3.11/site-packages/selenium/webdriver/firefox/webdriver.pyr    zWebDriver.__init__&   s+    #*8wwwyy$3'''))dlG44""$$ 	+&,&=&=&?&?G#&*G# L1133Ov7M7M7O7O*#|7! 4
 
 
	GGhHHHH 	 	 	IIKKK	  s   &#D
 
 D*c                     	 t                                                       n# t          $ r Y nw xY w| j                                         dS # | j                                         w xY w)z=Closes the browser and shuts down the GeckoDriver executable.N)r   r"   r!   r   stop)r$   r'   s    r(   r"   zWebDriver.quitN   sq    	 GGLLNNNN 	 	 	D	 LDLs!    $ A 
1A 1A A*c                 6    |                      dd|i           d S )NSET_CONTEXTcontextexecute)r$   r-   s     r(   set_contextzWebDriver.set_contextX   s!    ]Y$899999    c              #      K   |                      d                              d          }|                     |           	 dV  |                     |           dS # |                     |           w xY w)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 ...
        GET_CONTEXTvalueN)r/   popr0   )r$   r-   initial_contexts      r(   r-   zWebDriver.context[   s}       ,,}5599'BB!!!	.EEE_-----D_----s   A A3Fc           	      j   t           j                            |          rt                      }t           j                            |          }t          |          dz   }t          j        |dt          j        d          5 }t          j	        |          D ]I\  }}}|D ]@}	t           j        
                    ||	          }
|                    |
|
|d                    AJ	 ddd           n# 1 swxY w Y   t          j        |                                                              d          }nat!          |d          5 }t          j        |                                                              d          }ddd           n# 1 swxY w Y   ||d}|                     d	|          d
         S )a  Installs Firefox addon.

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

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

        :Usage:
            ::

                driver.install_addon('/path/to/firebug.xpi')
        r   wF)strict_timestampsNzUTF-8rb)addon	temporaryINSTALL_ADDONr4   )osr   isdirr   normpathlenzipfileZipFileZIP_DEFLATEDwalkjoinwritebase64	b64encodegetvaluedecodeopenreadr/   )r$   r   r<   fp	path_rootzippedbase_filesfylefilenamer;   filepayloads                 r(   install_addonzWebDriver.install_addonq   s#    7== 	FB7##D))DD		AIS'*>RWXXX E\b&(gdmm E END!U % E E#%7<<d#;#;Xx	

/CDDDDEEE E E E E E E E E E E E E E E
 $R[[]]33::7CCEEdD!! FT(55<<WEEF F F F F F F F F F F F F F F "	::||OW55g>>s%   AC..C25C2:F		FFc                 6    |                      dd|i           dS )zUninstalls Firefox addon using its identifier.

        :Usage:
            ::

                driver.uninstall_addon('addon@foo.com')
        UNINSTALL_ADDONidNr.   )r$   
identifiers     r(   uninstall_addonzWebDriver.uninstall_addon   s$     	&z(:;;;;;r1   c                 b   |                                                     d          st          j        dt                     |                                 }	 t          |d          5 }|                    |           ddd           n# 1 swxY w Y   n# t          $ r Y ~dS w xY w~n# ~w xY wdS )a  Saves a full document screenshot of the current window to a PNG
        image file. Returns False if there is any IOError, else returns True.
        Use full paths in your filename.

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

        :Usage:
            ::

                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_pngrL   rG   OSError)r$   rU   pngfs       r(    get_full_page_screenshot_as_filez*WebDriver.get_full_page_screenshot_as_file   s    ~~((00 	Mp   2244	h%%                	 	 		 GGGGtsN   B 'B	=B 	BB BB B) 
B$B) #B$$B) )B,c                 ,    |                      |          S )a  Saves a full document screenshot of the current window to a PNG
        image file. Returns False if there is any IOError, else returns True.
        Use full paths in your filename.

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

        :Usage:
            ::

                driver.save_full_page_screenshot('/Screenshots/foo.png')
        )ri   )r$   rU   s     r(   save_full_page_screenshotz#WebDriver.save_full_page_screenshot   s     44X>>>r1   c                 t    t          j        |                                                     d                    S )zGets the full document screenshot of the current window as a binary
        data.

        :Usage:
            ::

                driver.get_full_page_screenshot_as_png()
        ascii)rH   	b64decode"get_full_page_screenshot_as_base64encoder$   s    r(   re   z)WebDriver.get_full_page_screenshot_as_png   s0      G G I I P PQX Y YZZZr1   c                 8    |                      d          d         S )zGets the full document screenshot of the current window as a base64
        encoded string which is useful in embedded images in HTML.

        :Usage:
            ::

                driver.get_full_page_screenshot_as_base64()
        FULL_PAGE_SCREENSHOTr4   r.   rq   s    r(   ro   z,WebDriver.get_full_page_screenshot_as_base64   s     ||233G<<r1   )NNT)r   N)F)__name__
__module____qualname____doc__CONTEXT_CHROMECONTEXT_CONTENTr   r
   boolr    r"   r0   r   r-   strrX   r]   ri   rk   bytesre   ro   __classcell__)r'   s   @r(   r   r       sw       GGNO  	&  & &  &  	& 
 
&  &  &  &  &  & P           : : : : . . ^.* ?  ?c  ?  ?  ?  ?D< < < <D    :?T ? ? ? ? 	[ 	[ 	[ 	[ 	[	=C 	= 	= 	= 	= 	= 	= 	= 	=r1   r   )rH   r>   rb   rB   
contextlibr   ior   'selenium.webdriver.common.driver_finderr   #selenium.webdriver.remote.webdriverr   RemoteWebDriverr   r   remote_connectionr	   r   r
    r1   r(   <module>r      s   "  				   % % % % % %       @ @ @ @ @ @ L L L L L L       6 6 6 6 6 6      ~= ~= ~= ~= ~= ~= ~= ~= ~= ~=r1   