
    ,hU                        d dl mZ 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 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adad Z G d de      Z  G d de       Z!y)    )annotationsN)ABCMeta)	b64decode)encodebytes)md5)BytesIO)List)JavascriptException)WebDriverException)By)keys_to_typing   )Command)
ShadowRootc                     dj                  t        j                  d      d d       } t        j                  | d      j                  d      at        j                  | d      j                  d      ay )N.zgetAttribute.jsutf8zisDisplayed.js)join__name__splitpkgutilget_datadecodegetAttribute_jsisDisplayed_js)_pkgs    f/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/selenium/webdriver/remote/webelement.py_load_jsr   ,   s^     88HNN3',-D&&t->?FFvNO%%d,<=DDVLN    c                      e Zd ZdZy)BaseWebElementzAbstract Base Class for WebElement.

    ABC's will allow custom types to be registered as a WebElement to
    pass type checks.
    N)r   
__module____qualname____doc__ r    r   r"   r"   4   s     	r    r"   )	metaclassc                     e Zd ZdZd%dZd Zed&d       Zed&d       Zd%dZ	d%dZ
d%dZd'd	Zd&d
Zd(dZd)dZd)dZd*dZed+d       Zd)dZed,d       Zed,d       Zd&dZed,d       Zed,d       Zed&d       Zed&d       Zed&d       Zed-d       Zd)dZed        Zed&d       Zd Z d Z!d.d Z"e#jH                  dfd/d!Z%e#jH                  dfd0d"Z&d1d#Z'd$ Z(y)2
WebElementa  Represents a DOM element.

    Generally, all interesting operations that interact with a document will be
    performed through this interface.

    All method calls will do a freshness check to ensure that the element
    reference is still valid.  This essentially determines whether the
    element is still attached to the DOM.  If this test fails, then an
    ``StaleElementReferenceException`` is thrown, and all future calls to this
    instance will fail.
    c                     || _         || _        y N)_parent_id)selfparentid_s      r   __init__zWebElement.__init__K   s    r    c           	         dt        |       j                   dt        |       j                   d| j                  j                   d| j
                   d	S )N<r   z (session="z", element="z")>)typer#   r   r,   
session_idr-   r.   s    r   __repr__zWebElement.__repr__O   sN    4:(()4:+>+>*?{4<<KbKbJccoptpxpxoyy|}}r    c                F    | j                  t        j                        d   S )zThis element's ``tagName`` property.

        Returns:
        --------
        str : The tag name of the element.

        Example:
        --------
        >>> element = driver.find_element(By.ID, 'foo')
        value)_executer   GET_ELEMENT_TAG_NAMEr6   s    r   tag_namezWebElement.tag_nameR   s     }}W99:7CCr    c                F    | j                  t        j                        d   S )zThe text of the element.

        Returns:
        --------
        str : The text of the element.

        Example:
        --------
        >>> element = driver.find_element(By.ID, 'foo')
        >>> print(element.text)
        r9   )r:   r   GET_ELEMENT_TEXTr6   s    r   textzWebElement.text`   s     }}W556w??r    c                B    | j                  t        j                         y)zClicks the element.

        Example:
        --------
        >>> element = driver.find_element(By.ID, 'foo')
        >>> element.click()
        N)r:   r   CLICK_ELEMENTr6   s    r   clickzWebElement.clicko        	g++,r    c                |    d}	 | j                   j                  ||        y# t        $ r}t        d      |d}~ww xY w)zSubmits a form.

        Example:
        --------
        >>> form = driver.find_element(By.NAME, 'login')
        >>> form.submit()
        a  /* submitForm */var form = arguments[0];
while (form.nodeName != "FORM" && form.parentNode) {
  form = form.parentNode;
}
if (!form) { throw Error('Unable to find containing form element'); }
if (!form.ownerDocument) { throw Error('Unable to find owning document'); }
var e = form.ownerDocument.createEvent('Event');
e.initEvent('submit', true, true);
if (form.dispatchEvent(e)) { HTMLFormElement.prototype.submit.call(form) }
z=To submit an element, it must be nested inside a form elementN)r,   execute_scriptr
   r   )r.   scriptexcs      r   submitzWebElement.submity   sH    [ 		oLL''5" 	o$%deknn	os   ! 	;6;c                B    | j                  t        j                         y)zClears the text if it's a text entry element.

        Example:
        --------
        >>> text_field = driver.find_element(By.NAME, 'username')
        >>> text_field.clear()
        N)r:   r   CLEAR_ELEMENTr6   s    r   clearzWebElement.clear   rC   r    c                    	 | j                  t        j                  d|i      d   S # t        $ r  | j                  j                  d| |      cY S w xY w)ai  Gets the given property of the element.

        Parameters:
        -----------
        name : str
            - Name of the property to retrieve.

        Returns:
        -------
        str | bool | WebElement | dict : The value of the property.

        Example:
        -------
        >>> text_length = target_element.get_property("text_length")
        namer9   z!return arguments[0][arguments[1]])r:   r   GET_ELEMENT_PROPERTYr   r/   rE   r.   rM   s     r   get_propertyzWebElement.get_property   sU     	_==!=!=~NwWW! 	_;;--.QSWY]^^	_s   $' &AAc                L    | j                  t        j                  d|i      d   S )a  Gets the given attribute of the element. Unlike
        :func:`~selenium.webdriver.remote.BaseWebElement.get_attribute`, this
        method only returns attributes declared in the element's HTML markup.

        Parameters:
        -----------
        name : str
            - Name of the attribute to retrieve.

        Returns:
        -------
        str : The value of the attribute.

        Example:
        -------
        >>> text_length = target_element.get_dom_attribute("class")
        rM   r9   )r:   r   GET_ELEMENT_ATTRIBUTErO   s     r   get_dom_attributezWebElement.get_dom_attribute   s$    $ }}W::VTNKGTTr    c                p    t         
t                | j                  j                  dt          d| |      }|S )a  Gets the given attribute or property of the element.

        This method will first try to return the value of a property with the
        given name. If a property with that name doesn't exist, it returns the
        value of the attribute with the same name. If there's no attribute with
        that name, ``None`` is returned.

        Values which are considered truthy, that is equals "true" or "false",
        are returned as booleans.  All other non-``None`` values are returned
        as strings.  For attributes or properties which do not exist, ``None``
        is returned.

        To obtain the exact value of the attribute or property,
        use :func:`~selenium.webdriver.remote.BaseWebElement.get_dom_attribute` or
        :func:`~selenium.webdriver.remote.BaseWebElement.get_property` methods respectively.

        Parameters:
        -----------
        name : str
            - Name of the attribute/property to retrieve.

        Returns:
        -------
        str | bool | None : The value of the attribute/property.

        Example:
        --------
        >>> # Check if the "active" CSS class is applied to an element.
        >>> is_active = "active" in target_element.get_attribute("class")
        z/* getAttribute */return ().apply(null, arguments);)r   r   r/   rE   )r.   rM   attribute_values      r   get_attributezWebElement.get_attribute   s?    > "J++44((99RSUY[_
 r    c                F    | j                  t        j                        d   S )a  Returns whether the element is selected.

        Example:
        --------
        >>> is_selected = element.is_selected()

        Notes:
        ------
            - This method is generally used on checkboxes, options in a select
            and radio buttons.
        r9   )r:   r   IS_ELEMENT_SELECTEDr6   s    r   is_selectedzWebElement.is_selected   s     }}W889'BBr    c                F    | j                  t        j                        d   S )zReturns whether the element is enabled.

        Example:
        --------
        >>> is_enabled = element.is_enabled()
        r9   )r:   r   IS_ELEMENT_ENABLEDr6   s    r   
is_enabledzWebElement.is_enabled   s     }}W778AAr    c                     j                   j                  rt        t         fddj	                  t        t
        |            j                  d                  }d|vrCg }|D ]"  }|j                   j                  |             $ t        dj	                  |            } j                  t        j                  dj	                  t        |            t        |      d       y)a  Simulates typing into the element.

        Parameters:
        -----------
        value : str
            - A string for typing, or setting form fields.  For setting
            file inputs, this could be a local file path.

        Notes:
        ------
            - Use this to send simple key events or to fill out form fields
            - This can also be used to set file inputs.

        Examples:
        --------
        To send a simple key event::
        >>> form_textfield = driver.find_element(By.NAME, 'username')
        >>> form_textfield.send_keys("admin")

        or to set a file input field::
        >>> file_input = driver.find_element(By.NAME, 'profilePic')
        >>> file_input.send_keys("path/to/profilepic.gif")
        >>> # Generally it's better to wrap the file path in one of the methods
        >>> # in os.path to return the actual path to support cross OS testing.
        >>> # file_input.send_keys(os.path.abspath("path/to/profilepic.gif"))
        >>> # When using Cygwin, the path need to be provided in Windows format.
        >>> # file_input.send_keys(f"C:/cygwin{os.path.abspath('path/to/profilepic.gif').replace('/', '\')}")
        c                `    j                   j                  j                  t        |             S r+   )r/   file_detectoris_local_filestr)keys_to_sendr.   s    r   <lambda>z&WebElement.send_keys.<locals>.<lambda>%  s#    )B)B)P)PQTUaQb)c r     
N)r?   r9   )r/   
_is_remotelistmapr   rb   r   append_uploadtupler:   r   SEND_KEYS_TO_ELEMENTr   )r.   r9   local_filesremote_filesfiles   `    r   	send_keyszWebElement.send_keys  s    > ;;!!cGGCUO,2248K ;&!' <D ''T(:;<dii56((277>%;P3Q\jkp\q*r	
r    c                F    | j                  t        j                        d   S )a  Returns a shadow root of the element if there is one or an error.
        Only works from Chromium 96, Firefox 96, and Safari 16.4 onwards.

        Returns:
        -------
        ShadowRoot : object

        Raises:
        -------
        NoSuchShadowRoot - if no shadow root was attached to element

        Example:
        --------
        >>> try:
        ...     shadow_root = element.shadow_root
        >>> except NoSuchShadowRoot:
        ...     print("No shadow root attached to element")
        r9   )r:   r   GET_SHADOW_ROOTr6   s    r   shadow_rootzWebElement.shadow_root3  s    ( }}W445g>>r    c                j    t         
t                | j                  j                  dt          d|       S )zWhether the element is visible to a user.

        Example:
        --------
        >>> is_displayed = element.is_displayed()
        z/* isDisplayed */return (rU   )r   r   r/   rE   r6   s    r   is_displayedzWebElement.is_displayedJ  s3     !J{{)),EnEUUn*oquvvr    c                    | j                  t        j                  d| gd      d   }t        |d         t        |d         dS )a  THIS PROPERTY MAY CHANGE WITHOUT WARNING. Use this to discover where
        on the screen an element is so that we can click it. This method should
        cause the element to be scrolled into view.

        Returns:
        --------
        dict: the top lefthand corner location on the screen, or zero
            coordinates if the element is not visible.

        Example:
        --------
        >>> loc = element.location_once_scrolled_into_view
        zNarguments[0].scrollIntoView(true); return arguments[0].getBoundingClientRect())rF   argsr9   xyry   rz   )r:   r   W3C_EXECUTE_SCRIPTround)r.   old_locs     r    location_once_scrolled_into_viewz+WebElement.location_once_scrolled_into_viewV  sQ     --&&j
  73<(uWS\/BCCr    c                `    | j                  t        j                        d   }|d   |d   d}|S )zThe size of the element.

        Returns:
        --------
        dict: The width and height of the element.

        Example:
        --------
        >>> size = element.size
        r9   heightwidth)r   r   r:   r   GET_ELEMENT_RECT)r.   sizenew_sizes      r   r   zWebElement.sizen  s4     }}W556w?"8ntG}Er    c                L    | j                  t        j                  d|i      d   S )aX  The value of a CSS property.

        Parameters:
        -----------
        property_name : str
            - The name of the CSS property to get the value of.

        Returns:
        --------
        str : The value of the CSS property.

        Example:
        --------
        >>> value = element.value_of_css_property('color')
        propertyNamer9   )r:   r   !GET_ELEMENT_VALUE_OF_CSS_PROPERTY)r.   property_names     r   value_of_css_propertyz WebElement.value_of_css_property~  s'      }}WFFYfHghipqqr    c                    | j                  t        j                        d   }t        |d         t        |d         d}|S )zThe location of the element in the renderable canvas.

        Returns:
        --------
        dict: The x and y coordinates of the element.

        Example:
        --------
        >>> loc = element.location
        r9   ry   rz   r{   )r:   r   r   r}   )r.   r~   new_locs      r   locationzWebElement.location  s>     -- 8 89'Bgcl+%2EFr    c                F    | j                  t        j                        d   S )zA dictionary with the size and location of the element.

        Returns:
        --------
        dict: The size and location of the element.

        Example:
        --------
        >>> rect = element.rect
        r9   r   r6   s    r   rectzWebElement.rect  s     }}W556w??r    c                F    | j                  t        j                        d   S )zReturns the ARIA role of the current web element.

        Returns:
        --------
        str : The ARIA role of the element.

        Example:
        --------
        >>> role = element.aria_role
        r9   )r:   r   GET_ELEMENT_ARIA_ROLEr6   s    r   	aria_rolezWebElement.aria_role  s     }}W::;GDDr    c                F    | j                  t        j                        d   S )zReturns the ARIA Level of the current webelement.

        Returns:
        --------
        str : The ARIA Level of the element.

        Example:
        --------
        >>> name = element.accessible_name
        r9   )r:   r   GET_ELEMENT_ARIA_LABELr6   s    r   accessible_namezWebElement.accessible_name  s     }}W;;<WEEr    c                F    | j                  t        j                        d   S )a  Gets the screenshot of the current element as a base64 encoded
        string.

        Returns:
        --------
        str : The screenshot of the element as a base64 encoded string.

        Example:
        --------
        >>> img_b64 = element.screenshot_as_base64
        r9   )r:   r   ELEMENT_SCREENSHOTr6   s    r   screenshot_as_base64zWebElement.screenshot_as_base64  s     }}W778AAr    c                J    t        | j                  j                  d            S )zGets the screenshot of the current element as a binary data.

        Returns:
        --------
        bytes : The screenshot of the element as binary data.

        Example:
        --------
        >>> element_png = element.screenshot_as_png
        ascii)r   r   encoder6   s    r   screenshot_as_pngzWebElement.screenshot_as_png  s      2299'BCCr    c                "   |j                         j                  d      st        j                  dt               | j
                  }	 t        |d      5 }|j                  |       ddd       ~y# 1 sw Y   xY w# t        $ r Y ~yw xY w# ~w xY w)a2  Saves a screenshot of the current element to a PNG image file.
        Returns False if there is any IOError, else returns True. Use full
        paths in your filename.

        Returns:
        --------
        bool : True if the screenshot was saved successfully, False otherwise.

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

        Element:
        --------
        >>> element.screenshot('/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UserWarningr   openwriteOSError)r.   filenamepngfs       r   
screenshotzWebElement.screenshot  s    & ~~((0MMp $$	h% 
   		 s<   A; A/%A; /A84A; ;	BB BB Bc                    | j                   S )zInternal reference to the WebDriver instance this element was found
        from.

        Example:
        --------
        >>> element = driver.find_element(By.ID, 'foo')
        >>> parent_element = element.parent
        )r,   r6   s    r   r/   zWebElement.parent	  s     ||r    c                    | j                   S )a4  Internal ID used by selenium.

        This is mainly for internal use. Simple use cases such as checking if 2
        webelements refer to the same element, can be done using ``==``::

        Example:
        --------
        >>> if element1 == element2:
        ...     print("These 2 are equal")
        )r-   r6   s    r   idzWebElement.id  s     xxr    c                P    t        |d      xr | j                  |j                  k(  S )Nr   )hasattrr-   r   r.   elements     r   __eq__zWebElement.__eq__#  s!    w%@$((gjj*@@r    c                &    | j                  |       S r+   )r   r   s     r   __ne__zWebElement.__ne__&  s    ;;w'''r    Nc                `    |si }| j                   |d<   | j                  j                  ||      S )a  Executes a command against the underlying HTML element.

        Parameters:
        -----------
        command : any
            The name of the command to _execute as a string.

        params : dict
            A dictionary of named Parameters to send with the command.

        Returns:
        -------
          The command's JSON response loaded into a dictionary object.
        r   )r-   r,   execute)r.   commandparamss      r   r:   zWebElement._execute*  s0     Fxxt||##GV44r    c                    | j                   j                  j                  ||      \  }}| j                  t        j
                  ||d      d   S )a  Find an element given a By strategy and locator.

        Parameters:
        -----------
        by : selenium.webdriver.common.by.By
            The locating strategy to use. Default is `By.ID`. Supported values include:
            - By.ID: Locate by element ID.
            - By.NAME: Locate by the `name` attribute.
            - By.XPATH: Locate by an XPath expression.
            - By.CSS_SELECTOR: Locate by a CSS selector.
            - By.CLASS_NAME: Locate by the `class` attribute.
            - By.TAG_NAME: Locate by the tag name (e.g., "input", "button").
            - By.LINK_TEXT: Locate a link element by its exact text.
            - By.PARTIAL_LINK_TEXT: Locate a link element by partial text match.
            - RelativeBy: Locate elements relative to a specified root element.

        Example:
        --------
        element = driver.find_element(By.ID, 'foo')

        Returns:
        -------
        WebElement
            The first matching `WebElement` found on the page.
        usingr9   r9   )r,   locator_converterconvertr:   r   FIND_CHILD_ELEMENTr.   byr9   s      r   find_elementzWebElement.find_element>  sG    4 LL22::2uE	E}}W772PU9VWX_``r    c                    | j                   j                  j                  ||      \  }}| j                  t        j
                  ||d      d   S )a  Find elements given a By strategy and locator.

        Parameters:
        -----------
        by : selenium.webdriver.common.by.By
            The locating strategy to use. Default is `By.ID`. Supported values include:
            - By.ID: Locate by element ID.
            - By.NAME: Locate by the `name` attribute.
            - By.XPATH: Locate by an XPath expression.
            - By.CSS_SELECTOR: Locate by a CSS selector.
            - By.CLASS_NAME: Locate by the `class` attribute.
            - By.TAG_NAME: Locate by the tag name (e.g., "input", "button").
            - By.LINK_TEXT: Locate a link element by its exact text.
            - By.PARTIAL_LINK_TEXT: Locate a link element by partial text match.
            - RelativeBy: Locate elements relative to a specified root element.

        Example:
        --------
        >>> element = driver.find_elements(By.ID, 'foo')

        Returns:
        -------
        List[WebElement]
            list of `WebElements` matching locator strategy found on the page.
        r   r9   )r,   r   r   r:   r   FIND_CHILD_ELEMENTSr   s      r   find_elementszWebElement.find_elements[  sG    4 LL22::2uE	E}}W88BQV:WXY`aar    c                z    t        t        | j                  j                  d            j	                         d      S )Nutf-8   )intmd5_hashr-   r   	hexdigestr6   s    r   __hash__zWebElement.__hash__x  s*    8DHHOOG45??A2FFr    c                @   t               }t        j                  |dt        j                        }|j	                  |t
        j                  j                  |      d          |j                          t        |j                               }t        |t              s|j                  d      }	 | j                  t        j                   d|i      d   S # t"        $ rB}dt        |      v r|cY d }~S dt        |      v r|cY d }~S dt        |      v r|cY d }~S  d }~ww xY w)	Nwr   r   rp   r9   zUnrecognized command: POSTzCommand not found: POST z.{"status":405,"value":["GET","HEAD","DELETE"]})r   zipfileZipFileZIP_DEFLATEDr   ospathr   closer   getvalue
isinstancerb   r   r:   r   UPLOAD_FILEr   )r.   r   fpzippedcontentes         r   rk   zWebElement._upload{  s    YS'*>*>?Xrww}}X6q9:bkkm,'3'nnW-G		==!4!4vw6GHQQ! 	+s1v5)SV3?3q6I	s<   -$C 	DD)D/D=DDDDD)returnNone)r   rb   )r   zstr | bool | WebElement | dict)r   z
str | None)r   bool)r9   rb   r   r   )r   r   )r   dict)r   bytesr+   )r   r)   )r   zList[WebElement])r   r   ))r   r#   r$   r%   r1   r7   propertyr<   r?   rB   rH   rK   rP   rS   rW   rZ   r]   rq   rt   rv   r   r   r   r   r   r   r   r   r   r   r/   r   r   r   r:   r   IDr   r   r   rk   r&   r    r   r)   r)   >   s   
~ D D @ @-o2-_,U($LCB.
` ? ?,
w D D.  r$   @ @ E E F F B B D D D 	 	  A(5( !ee4 a:  "uuD b:Gr    r)   )"
__future__r   r   r   r   r   abcr   base64r   r   hashlibr   r   ior   typingr	   selenium.common.exceptionsr
   r   selenium.webdriver.common.byr   selenium.webdriver.common.utilsr   r   r   
shadowrootr   r   r   r   r"   r)   r&   r    r   <module>r      sf   " # 	       #   : 9 + :  " M	w 	N	 N	r    