a
    ҏie                     @   s  d dl Z d dlZd dlmZ d dlmZmZmZmZm	Z	m
Z
mZmZmZ d dlmZ d dlmZmZmZ d dlmZmZmZmZ d dlmZmZ d dlmZ d d	lmZ d d
l m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) d dl*m+Z+m,Z,m-Z-m.Z. d dl/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 d dl:m;Z; d dl<m=Z= d dl>m?Z? ej@dkrZd dlmAZA nd dlBmAZA erxd dlCmDZD G dd deZEdS )    N)Path)	TYPE_CHECKINGAnyDictListOptionalPatternSetUnioncast)EventEmitter)AriaRoleFilePayloadPosition)ChannelOwnerfilter_nonefrom_channelfrom_nullable_channel)ElementHandleconvert_select_option_values)Error)EventContextManagerImpl)	DocumentLoadStateFrameNavigatedEventKeyboardModifierMouseButtonURLMatch
URLMatcherasync_readfilelocals_to_paramsmonotonic_time)JSHandleSerializableparse_resultserialize_argument)
FrameLocatorLocatorget_by_alt_text_selectorget_by_label_selectorget_by_placeholder_selectorget_by_role_selectorget_by_test_id_selectorget_by_text_selectorget_by_title_selectortest_id_attribute_name)Response)convert_input_files)Waiter)      )Literal)Pagec                       s   e Zd Zeeeedd fddZedddZdeeddd	d
Z	e
ddddZeedddZeddddZdeeeeee dddZdeeedddZdeeeee dddZdeeeddddZded edd d!d"Zdeedd d#d$Zedd%d&Zdeee d'd(d)Z!deee"d'd*d+Z#dee$ee d,d-d.Z%ee&e dd/d0Z'dee$eed1 ee d2d3d4Z(dee$ee$d5d6d7Z)dee$ee$d5d8d9Z*dee$ee$d5d:d;Z+dee$ee$d5d<d=Z,dee$ee$d5d>d?Z-dee$ee$d5d@dAZ.deeee$eddBdCdDZ/deeee$e dEdFdGZ0deeee dHdIdJZ1eddKdLZ2deeeddMdNdOZ3eeddPdQZ4eeddRdSZ5eed  ddTdUZ6ee&d  ddVdWZ7e$ddXdYZ8dee9ee:f eeedZd[d\Z;dee9ee:f eed]d^d_Z<dee&e= e>ee?eee$e$e$e$dd`dadbZ@dee&e= e>ee?ee$e$e$e$ddcdddeZAdee&e= e>ee$e$e$e$ddf	dgdhZBdeeee$e$e$ddidjdkZCdee9eeDe f e9eeDe f eEeEeEdldmdnZFde9eeDe f e$dodpdqdrZGde9eeDe f e$dodpdsdtZHde9eeDe f e$dodpdudvZIdeJe$e$e$e$ee9eeDe f e$e$e$dodwdxdyZKe9eeDe f dodzd{d|ZLde9eeDe f e$dodpd}d~ZMde9eeDe f e$dodpddZNeeOdddZPdee$edd5ddZQdee$eee d5ddZRdee$eed5ddZSdee$eed5ddZTdeee$eee dddZUdee&e= e>ee$e$e$e$dd	ddZVdeee>e>e$e$e$ee$dd
ddZWdee9ee&e f e9ee&e f e9ee&e f e9de&d f ee$e$e$e&e d
ddZXdee$eed5ddZYdee9ee:eZe&e9ee:f  e&eZ f e$ee$ddddZ[deeee$ee$ddddZ\deeee$ee$ddddZ]dee>ee$e$e$e$ddddZ^dee>ee$e$e$e$ddddZ_eddddZ`deeee9eed f e"dddZaedddZbdee$e>ee$e$e$e$dd	ddZceddddZd  ZeS )FrameN)parenttypeguidinitializerreturnc                    s   t  |||| t|d _ jr6 jj  |d  _|d  _d _	g  _d  _
t|d  _t  _ jd fdd  jd	 fd
d d S )NZparentFramenameurlFZ
loadStates	loadstatec                    s     | d| dS )Naddremove)_on_load_stategetparamsself G/home/Claro/venv/lib/python3.9/site-packages/playwright/_impl/_frame.py<lambda>[       z Frame.__init__.<locals>.<lambda>	navigatedc                    s
     | S N)_on_frame_navigatedrC   rE   rG   rH   rI   _   rJ   )super__init__r   rB   _parent_frame_child_framesappend_name_url	_detached_pageset_load_statesr   _event_emitter_channelon)rF   r7   r8   r9   r:   	__class__rE   rH   rO   K   s&    



zFrame.__init__r;   c                 C   s   d| j  d| jdS )Nz<Frame name=z url=>)r<   r=   rE   rG   rG   rH   __repr__b   s    zFrame.__repr__)r?   r@   r;   c                 C   s   |r | j | | jd| n|r:|| j v r:| j | | js^|dkr^| jr^| jd| j | js|dkr| jr| jd| j d S )Nr>   loaddomcontentloaded)rX   r?   rY   emitr@   rP   rV   )rF   r?   r@   rG   rG   rH   rA   e   s    zFrame._on_load_stateeventr;   c                 C   sB   |d | _ |d | _| jd| d|vr>| jr>| jd|  d S )Nr=   r<   rK   errorZframenavigated)rT   rS   rY   rc   rV   )rF   re   rG   rG   rH   rM   r   s
    

zFrame._on_frame_navigated)selectorr;   c                    s   | j dd|iI d H S )NZ
queryCountrg   rZ   sendrF   rg   rG   rG   rH   _query_county   s    zFrame._query_countr5   c                 C   s   | j s
J | j S rL   )rV   rE   rG   rG   rH   page|   s    
z
Frame.page)r=   timeout	waitUntilrefererr;   c                    s(   t tt t| jdtt I d H S )Ngoto)r   r   r/   r   rZ   ri   r   locals)rF   r=   rm   rn   ro   rG   rG   rH   rp      s    z
Frame.goto)	wait_namerm   r;   c                    s    j s
J t j d| }| j d fdd | j dtd | j dtd fd	d |d u rz j j }||d
| d |S )Nzframe.closec                      s   t t j S rL   )r   r5   rV   Z_close_error_with_reasonrG   rE   rG   rH   rI      rJ   z0Frame._setup_navigation_waiter.<locals>.<lambda>Zcrashz'Navigation failed because page crashed!ZframedetachedzNavigating frame was detached!c                    s   |  kS rL   rG   )framerE   rG   rH   rI      rJ   zTimeout zms exceeded.)rV   r1   Zreject_on_eventr   _timeout_settingsnavigation_timeoutZreject_on_timeout)rF   rr   rm   waiterrG   rE   rH   _setup_navigation_waiter   s(    


zFrame._setup_navigation_waiter)r=   
wait_untilrm   r;   c                    s   j s
J sd|d u r&j j }t |  d||rLd| dnd}d| d d |rtj jj	d	|nd t
td
fdd}jjd|d tt d fdd}tt| S )Nra   expect_navigationz to "" zwaiting for navigationz until ''baseURLrd   c                    s8   |  drdS d| d  d   p6 | d S )Nrf   Tz  navigated to "r=   r{   )rB   logmatches)re   )matcherrw   rG   rH   	predicate   s    
z*Frame.expect_navigation.<locals>.predicaterK   )r   r^   c                     s     I d H } d| v r"t| d jvrR t  }|dkrRj|dI d H  d| v rd| d v rt| d d }| I d H S d S )Nrf   r   staterm   ZnewDocumentrequest)resultr   rX   r    _wait_for_load_state_implr   response)re   tr   )deadlinerF   ry   rw   rG   rH   continuation   s    

z-Frame.expect_navigation.<locals>.continuation)rV   ru   rv   r    rx   r   r   _browser_context_optionsrB   r   boolwait_for_eventrY   r   r/   r   asyncioZcreate_task)rF   r=   ry   rm   Zto_urlr   r   rG   )r   r   rF   ry   rw   rH   rz      s*    

zFrame.expect_navigationc              	      s   | j s
J t| j jjd|}|| jrD| j||dI d H  d S | j|||d4 I d H  W d   I d H  q1 I d H s~0    Y  d S )Nr~   r   )r=   ry   rm   )	rV   r   r   r   rB   r   r=   r   rz   )rF   r=   ry   rm   r   rG   rG   rH   wait_for_url   s    
zFrame.wait_for_url)rb   ra   networkidle)r   rm   r;   c                    s   |  ||I d H S rL   )r   )rF   r   rm   rG   rG   rH   wait_for_load_state   s    zFrame.wait_for_load_statec                    s    sd  dvrt d| d| | jv rLd  d d  n&ttd fdd	}| jd
| 	 I d H  d S )Nra   )ra   rb   r   commitzAstate: expected one of (load|domcontentloaded|networkidle|commit)r   z  not waiting, "z" event already fired)actual_stater;   c                    s    d|  d |  kS )Nr{   z" event fired)r   )r   r   rw   rG   rH   handle_load_state_event   s    z@Frame._wait_for_load_state_impl.<locals>.handle_load_state_eventr>   )
r   rx   rX   r   Z_fulfillstrr   r   rY   r   )rF   r   rm   r   rG   r   rH   r      s"    
zFrame._wait_for_load_state_implc                    s   t | jdI d H S )NZframeElement)r   rZ   ri   rE   rG   rG   rH   frame_element  s    zFrame.frame_element)
expressionargr;   c                    s$   t | jdt|t|dI d H S )NZevaluateExpressionr   r   r#   rZ   ri   dictr$   rF   r   r   rG   rG   rH   evaluate  s    zFrame.evaluatec                    s$   t | jdt|t|dI d H S )NZevaluateExpressionHandler   )r   rZ   ri   r   r$   r   rG   rG   rH   evaluate_handle  s    zFrame.evaluate_handle)rg   strictr;   c                    s   t | jdtt I d H S )NZquerySelectorr   rZ   ri   r   rq   )rF   rg   r   rG   rG   rH   query_selector&  s    zFrame.query_selectorc              	      s$   t tt| jdt|dI d H S )NZquerySelectorAll)rg   )listmapr   rZ   ri   r   rj   rG   rG   rH   query_selector_all-  s    zFrame.query_selector_all)ZattachedZdetachedhiddenZvisible)rg   r   rm   r   r;   c                    s   t | jdtt I d H S )NZwaitForSelectorr   )rF   rg   r   rm   r   rG   rG   rH   wait_for_selector5  s    zFrame.wait_for_selector)rg   r   rm   r;   c                    s   | j dtt I d H S )NZ	isCheckedrZ   ri   r   rq   rF   rg   r   rm   rG   rG   rH   
is_checked@  s    zFrame.is_checkedc                    s   | j dtt I d H S )NZ
isDisabledr   r   rG   rG   rH   is_disabledE  s    zFrame.is_disabledc                    s   | j dtt I d H S )NZ
isEditabler   r   rG   rG   rH   is_editableJ  s    zFrame.is_editablec                    s   | j dtt I d H S )NZ	isEnabledr   r   rG   rG   rH   
is_enabledO  s    zFrame.is_enabledc                    s   | j dtt I d H S )NZisHiddenr   r   rG   rG   rH   	is_hiddenT  s    zFrame.is_hiddenc                    s   | j dtt I d H S )NZ	isVisibler   r   rG   rG   rH   
is_visibleY  s    zFrame.is_visible)rg   r8   	eventInitr   rm   r;   c                    s.   | j dtt||t|||dI d H  d S )NZdispatchEvent)rg   r8   r   r   rm   )rZ   ri   r   r   r$   )rF   rg   r8   r   r   rm   rG   rG   rH   dispatch_event^  s    zFrame.dispatch_event)rg   r   r   r   r;   c                    s,   t | jdtt||t||dI d H S )NZevalOnSelector)rg   r   r   r   )r#   rZ   ri   r   r   r$   )rF   rg   r   r   r   rG   rG   rH   eval_on_selectors  s    zFrame.eval_on_selector)rg   r   r   r;   c              	      s&   t | jdt||t|dI d H S )NZevalOnSelectorAll)rg   r   r   r   )rF   rg   r   r   rG   rG   rH   eval_on_selector_all  s    zFrame.eval_on_selector_allc                    s   | j dI d H S )Ncontentrh   rE   rG   rG   rH   r     s    zFrame.content)htmlrm   rn   r;   c                    s   | j dtt I d H  d S )NZ
setContentr   )rF   r   rm   rn   rG   rG   rH   set_content  s    zFrame.set_contentc                 C   s
   | j pdS Nr|   )rS   rE   rG   rG   rH   r<     s    z
Frame.namec                 C   s
   | j pdS r   )rT   rE   rG   rG   rH   r=     s    z	Frame.urlc                 C   s   | j S rL   )rP   rE   rG   rG   rH   parent_frame  s    zFrame.parent_framec                 C   s
   | j  S rL   )rQ   copyrE   rG   rG   rH   child_frames  s    zFrame.child_framesc                 C   s   | j S rL   )rU   rE   rG   rG   rH   is_detached  s    zFrame.is_detached)r=   pathr   r8   r;   c                    sR   t t }|r:t|I d H  d tt| |d< |d= t| jd|I d H S )Nz
//# sourceURL=r   r   ZaddScriptTag	r   rq   r   decoder   r   r   rZ   ri   )rF   r=   r   r   r8   rD   rG   rG   rH   add_script_tag  s    

zFrame.add_script_tag)r=   r   r   r;   c                    sV   t t }|r>t|I d H  d tt| d |d< |d= t| jd|I d H S )Nz
/*# sourceURL=z*/r   r   ZaddStyleTagr   )rF   r=   r   r   rD   rG   rG   rH   add_style_tag  s    

zFrame.add_style_tag)rg   	modifierspositiondelaybutton
clickCountrm   forcenoWaitAfterr   trialr;   c                    s   | j dtt I d H  d S )Nclickr   )rF   rg   r   r   r   r   r   rm   r   r   r   r   rG   rG   rH   r     s    zFrame.click)rg   r   r   r   r   rm   r   r   r   r   r;   c                    s   | j dtt I d H  d S )Ndblclickr   )rF   rg   r   r   r   r   rm   r   r   r   r   rG   rG   rH   r     s    zFrame.dblclick)	rg   r   r   rm   r   r   r   r   r;   c	           	         s   | j dtt I d H  d S )Ntapr   )	rF   rg   r   r   rm   r   r   r   r   rG   rG   rH   r     s    z	Frame.tap)rg   valuerm   r   r   r   r;   c                    s   | j dtt I d H  d S )Nfillr   )rF   rg   r   rm   r   r   r   rG   rG   rH   r     s    	z
Frame.fill)rg   has_texthas_not_texthashas_notr;   c                 C   s   t | |||||dS )N)r   r   r   r   )r&   )rF   rg   r   r   r   r   rG   rG   rH   locator  s    zFrame.locatorr&   )textexactr;   c                 C   s   |  t||dS N)r   )r   r'   rF   r   r   rG   rG   rH   get_by_alt_text  s    zFrame.get_by_alt_textc                 C   s   |  t||dS r   )r   r(   r   rG   rG   rH   get_by_label#  s    zFrame.get_by_labelc                 C   s   |  t||dS r   )r   r)   r   rG   rG   rH   get_by_placeholder(  s    zFrame.get_by_placeholder)rolecheckeddisabledexpandedincludeHiddenlevelr<   pressedselectedr   r;   c                 C   s"   |  t|||||||||	|
d
S )N)	r   r   r   r   r   r<   r   r   r   )r   r*   )rF   r   r   r   r   r   r   r<   r   r   r   rG   rG   rH   get_by_role-  s    zFrame.get_by_role)testIdr;   c                 C   s   |  tt |S rL   )r   r+   r.   )rF   r   rG   rG   rH   get_by_test_idI  s    zFrame.get_by_test_idc                 C   s   |  t||dS r   )r   r,   r   rG   rG   rH   get_by_textL  s    zFrame.get_by_textc                 C   s   |  t||dS r   )r   r-   r   rG   rG   rH   get_by_titleQ  s    zFrame.get_by_titlec                 C   s
   t | |S rL   )r%   rj   rG   rG   rH   frame_locatorV  s    zFrame.frame_locatorc                    s   | j dtt I d H  d S )Nfocusr   r   rG   rG   rH   r   Y  s    zFrame.focusc                    s   | j dtt I d H S )NZtextContentr   r   rG   rG   rH   text_content^  s    zFrame.text_contentc                    s   | j dtt I d H S )NZ	innerTextr   r   rG   rG   rH   
inner_textc  s    zFrame.inner_textc                    s   | j dtt I d H S )N	innerHTMLr   r   rG   rG   rH   
inner_htmlh  s    zFrame.inner_html)rg   r<   r   rm   r;   c                    s   | j dtt I d H S )NgetAttributer   )rF   rg   r<   r   rm   rG   rG   rH   get_attributem  s    zFrame.get_attribute)	rg   r   r   rm   r   r   r   r   r;   c	           	         s   | j dtt I d H  d S )Nhoverr   )	rF   rg   r   r   rm   r   r   r   r   rG   rG   rH   r   r  s    zFrame.hover)
sourcetargetsourcePositiontargetPositionr   r   r   rm   r   r;   c
           
         s   | j dtt I d H  d S )NZdragAndDropr   )
rF   r   r   r   r   r   r   r   rm   r   rG   rG   rH   drag_and_drop  s    zFrame.drag_and_dropr   )
rg   r   indexlabelelementrm   r   r   r   r;   c
              	      s<   t tf |||||	dt||||}
| jd|
I d H S )N)rg   rm   r   r   r   ZselectOption)r   r   r   rZ   ri   )rF   rg   r   r   r   r   rm   r   r   r   rD   rG   rG   rH   select_option  s    
zFrame.select_optionc                    s   | j dtt I d H S )NZ
inputValuer   r   rG   rG   rH   input_value  s    zFrame.input_value)rg   filesr   rm   r   r;   c              
      sB   t || jjI d H }| jdi t||||d|I d H  d S )NZsetInputFiles)rg   r   rm   r   )r0   rl   contextrZ   ri   r   )rF   rg   r   r   rm   r   Z	convertedrG   rG   rH   set_input_files  s    	zFrame.set_input_files)rg   r   r   r   rm   r   r;   c                    s   | j dtt I d H  d S )Nr8   r   )rF   rg   r   r   r   rm   r   rG   rG   rH   r8     s    	z
Frame.type)rg   keyr   r   rm   r   r;   c                    s   | j dtt I d H  d S )Npressr   )rF   rg   r   r   r   rm   r   rG   rG   rH   r     s    	zFrame.press)rg   r   rm   r   r   r   r   r;   c                    s   | j dtt I d H  d S )Ncheckr   rF   rg   r   rm   r   r   r   r   rG   rG   rH   r    s    
zFrame.checkc                    s   | j dtt I d H  d S )Nuncheckr   r  rG   rG   rH   r    s    
zFrame.uncheck)rm   r;   c                    s   | j dtt I d H  d S )NZwaitForTimeoutr   )rF   rm   rG   rG   rH   wait_for_timeout  s    zFrame.wait_for_timeoutraf)r   r   rm   pollingr;   c                    sf   t |tr |dkr td| tt }t||d< |d urN|dkrN||d< t| jd|I d H S )Nr  zUnknown polling option: r   ZpollingIntervalZwaitForFunction)	
isinstancer   r   r   rq   r$   r   rZ   ri   )rF   r   r   rm   r  rD   rG   rG   rH   wait_for_function  s    
zFrame.wait_for_functionc                    s   | j dI d H S )Ntitlerh   rE   rG   rG   rH   r	    s    zFrame.title)	rg   r   r   rm   r   r   r   r   r;   c	           	   	      sF   |r$| j |||||||dI d H  n| j|||||||dI d H  d S )N)rg   r   rm   r   r   r   r   )r  r  )	rF   rg   r   r   rm   r   r   r   r   rG   rG   rH   set_checked  s&    
zFrame.set_checkedc                    s   | j dd|iI d H  d S )NZ	highlightrg   rh   rj   rG   rG   rH   
_highlight(  s    zFrame._highlight)NN)NNN)N)NNN)NN)NN)NN)N)N)N)NNN)NN)NN)NN)NN)NN)NN)NNN)NN)N)NN)NNNN)NNN)
NNNNNNNNNN)	NNNNNNNNN)NNNNNNN)NNNN)NNNN)N)N)N)	NNNNNNNNN)N)N)NN)NN)NN)NN)NN)NNNNNNN)NNNNNNN)NNNNNNNN)NN)NNN)NNNN)NNNN)NNNNNN)NNNNNN)NNN)NNNNNN)f__name__
__module____qualname__r   r   r   rO   r`   r   rA   r   rM   intrk   propertyrl   floatr   r/   rp   r1   rx   r   r   rz   r   r4   r   r   r   r   r"   r   r   r!   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r<   r=   r   r   r   r
   r   r   r   r   r   r   r   r   r   r   r   r&   r   r   r   r   r   r   r   r   r   r%   r   r   r   r   r   r   r   r   r   r   r   r   r8   r   r  r  r  r  r	  r
  r  __classcell__rG   rG   r\   rH   r6   J   s         6                	            
                                                                                                                r6   )Fr   syspathlibr   typingr   r   r   r   r   r   r	   r
   r   Zpyeer   Z playwright._impl._api_structuresr   r   r   Zplaywright._impl._connectionr   r   r   r   Z playwright._impl._element_handler   r   Zplaywright._impl._errorsr   Z'playwright._impl._event_context_managerr   Zplaywright._impl._helperr   r   r   r   r   r   r   r   r    Zplaywright._impl._js_handler!   r"   r#   r$   Zplaywright._impl._locatorr%   r&   r'   r(   r)   r*   r+   r,   r-   r.   Zplaywright._impl._networkr/   Z)playwright._impl._set_input_files_helpersr0   Zplaywright._impl._waiterr1   version_infor4   Ztyping_extensionsZplaywright._impl._pager5   r6   rG   rG   rG   rH   <module>   s*   ,,0