
    $)f                     V    d dl Z d dlZd dlmZ d dlmZ d dlmZ dad Z	 G d d      Z
y)    N)asynccontextmanager)import_module)Byc                  (    t         st        d      a y y )Nz"selenium.webdriver.common.bidi.cdp)cdpr        Z/var/www/html/flask-app/venv/lib/python3.12/site-packages/selenium/webdriver/common/log.py
import_cdpr      s    @A r	   c                   T    e Zd ZdZddZedefd       Zed        Zedefd       Z	y)	LogzThis class allows access to logging APIs that use the new WebDriver Bidi
    protocol.

    This class is not to be used directly and should be used from the
    webdriver base classes.
    returnNc                 6   || _         |j                  | _        |j                  | _        |j                  | _        dj	                  t
        j                  d      d d       }t        j                  |d      j                  d      j                         | _        y )N.zmutation-listener.jsutf8)driversessionr   devtoolsjoin__name__splitpkgutilget_datadecodestrip_mutation_listener_js)selfr   bidi_session_pkgs       r
   __init__zLog.__init__*   sy    #++##$--xxs+CR01%,%5%5d<R%S%Z%Z[a%b%h%h%j"r	   c                N  K   | j                   j                  d      }|j                  | j                  j                  j                                d{    | j                   j                  d      }|j                  | j                  j                  j                                d{    |j                  | j                  j                  j                  d             d{    | j                  j                  | j                         |j                  | j                  j                  j                  | j                               d{   }| j                  j                  | j                  |       | j                  j                  d| j                          i }|j                  | j                  j                  j                        4 d{   }| ddd      d{    t        j                   j"                  j$                        }| j                  j'                  t(        j*                  d|d          }|s|j-                  d       |d   |d	<   |d
   |d<   |d   |d<   |d   |d<   y7 ,7 7 7 87 7 # 1 d{  7  sw Y   xY ww)aH  Listen for mutation events and emit them as they are found.

        :Usage:
             ::

               async with driver.log.mutation_events() as event:
                    pages.load("dynamic.html")
                    driver.find_element(By.ID, "reveal").click()
                    WebDriverWait(driver, 5)                        .until(EC.visibility_of(driver.find_element(By.ID, "revealed")))

                assert event["attribute_name"] == "style"
                assert event["current_value"] == ""
                assert event["old_value"] == "display:none;"
        page.enableNruntime.enable__webdriver_attributezreturn z*[data-__webdriver_id=targetr   elementnameattribute_namevaluecurrent_valueoldValue	old_value)r   get_session_contextexecuter   pageenableruntimeadd_bindingr   
pin_scriptr   &add_script_to_evaluate_on_new_documentexecute_scriptwait_forBindingCalledjsonloadsr*   payloadfind_elementsr   CSS_SELECTORappend)r   r0   r2   
script_keyeventevntr;   elementss           r
   mutation_eventszLog.mutation_events2   s#    $ xx++M:ll4==--446777((../?@oodmm33::<===oodmm33??@WXYYYt99:<<MMEEdF`F`a
 

 	t99:F""WT-G-G,H#IJ##DMM$9$9$G$GH 	 	DK	 	 **TZZ//0222??F\]dem]n\oDpqOOD!#A;i")&/!(!1o$Z0k+ 	8=Y
	 	 	 	 	s   AJ%J AJ%*J+;J%&J'A*J%J	BJ%JJ%J#J%.J/BJ%J%J%	J%J%J%J"JJ"J%c                  K   | j                   j                  d      }|j                  | j                  j                  j                                d{    | j                   j                  d      }|j                  | j                  j                  j                                d{    | j                  j                  j                  dd      }|j                  | j                  j                  j                        4 d{   }| ddd      d{    j                  j                  |_
        |j                  j                  |_        y7 7 7 U7 B# 1 d{  7  sw Y   RxY ww)a  Listen for JS errors and when the contextmanager exits check if
        there were JS Errors.

        :Usage:
             ::

                async with driver.log.add_js_error_listener() as error:
                    driver.find_element(By.ID, "throwing-mouseover").click()
                assert bool(error)
                assert error.exception_details.stack_trace.call_frames[0].function_name == "onmouseover"
        r#   Nr$   )r   r.   r/   r   r0   r1   r2   ExceptionThrownr7   r*   	timestampexception_details)r   r   js_exception	exceptions       r
   add_js_error_listenerzLog.add_js_error_listener\   s     ((..}=oodmm00779:::((../?@oodmm33::<===}},,<<T4H##DMM$9$9$I$IJ 	 	i	 	!*!:!:)2)J)J& 	;=	 	 	 	 	sn   AE7EAE7*E+AE7E	E7E"E7E <E7E7E7 E7"E4(E+)E40E7c                N  K   ddl m} | j                  j                  d      }|j	                  | j
                  j                  j                                d{    | j                  j                  d      }|j	                  | j
                  j                  j                                d{    ddd}|j                  | j
                  j                  j                        4 d{   }| ddd      d{    ||j                  k(  s#|j                  j                  j                  k(  rMj                  j                  d   j                  |d<   |j                  j                  d   j                  |d<   yy7 -7 7 7 # 1 d{  7  sw Y   xY ww)	a  Listen for certain events that are passed in.

        :Args:
         - event_type: The type of event that we want to look at.

        :Usage:
             ::

                async with driver.log.add_listener(Console.log) as messages:
                    driver.execute_script("console.log('I like cheese')")
                assert messages["message"] == "I love cheese"
        r   )Consoler#   Nr$   )messagelevelrM   rN   )&selenium.webdriver.common.bidi.consolerL   r   r.   r/   r   r0   r1   r2   r7   ConsoleAPICalledALLr*   type_args)r   
event_typerL   r   consolemessagess         r
   add_listenerzLog.add_listenert   sP     	C((..}=oodmm00779:::((../?@oodmm33::<==="T2##DMM$9$9$J$JK 	 	xM	 	 $
(8(8HNN<P<P(P!)!4!4Q!7!=!=GI'~~2215;;GG )Q 	;=	 	 	 	 	sn   AF%FAF%0F
1<F%-F.F%1F7F%FBF%
F%F%F%F"FF"F%)r   N)
r   
__module____qualname____doc__r!   r   dictrC   rJ   rW   r   r	   r
   r   r   "   sZ    k '1t '1 '1R K K. < < <r	   r   )r9   r   
contextlibr   	importlibr   selenium.webdriver.common.byr   r   r   r   r   r	   r
   <module>r_      s-   $   * # +
Bm< m<r	   