
    /_iO                        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	m
Z
 d dlmZ d dlmZ d dlmZ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)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    c/var/www/html/land_sniper/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    0   s     	r   r    )	metaclassc                     e Zd ZdZd&dZd Zed'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$jJ                  d fd0d"Z&e$jJ                  d fd1d#Z'd2d$Z(d% Z)y )3
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__G   s    r   c           	         dt        |       j                   dt        |       j                   d| j                   d| j                   d	S )N<r   z (session="z", element="z")>)typer!   r   
session_idr+   r,   s    r   __repr__zWebElement.__repr__K   sH    4:(()4:+>+>*?{4??J[[ghlhphpgqqtuur   c                .    | j                   j                  S r)   )r*   r3   r4   s    r   r3   zWebElement.session_idN   s    ||&&&r   c                F    | j                  t        j                        d   S )zThis element's `tagName` property.

        Returns:
            The tag name of the element.

        Example:
            element = driver.find_element(By.ID, "foo")
        value)_executer   GET_ELEMENT_TAG_NAMEr4   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:
            The text of the element.

        Example:
            element = driver.find_element(By.ID, "foo")
            print(element.text)
        r8   )r9   r   GET_ELEMENT_TEXTr4   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)r9   r   CLICK_ELEMENTr4   s    r   clickzWebElement.clickk        	g++,r   c                |    d}	 | j                   j                  ||        y# t        $ r}t        d      |d}~ww xY w)z}Submits 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.submitt   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)r9   r   CLEAR_ELEMENTr4   s    r   clearzWebElement.clear   rB   r   c                    	 | j                  t        j                  d|i      d   S # t        $ r  | j                  j                  d| |      cY S w xY w)a  Gets the given property of the element.

        Args:
            name: Name of the property to retrieve.

        Returns:
            The value of the property.

        Example:
            text_length = target_element.get_property("text_length")
        namer8   z!return arguments[0][arguments[1]])r9   r   GET_ELEMENT_PROPERTYr
   r-   rD   r,   rL   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  Get the HTML attribute value (not reflected properties) of the element.

        Returns only attributes declared in the element's HTML markup, unlike
        `selenium.webdriver.remote.BaseWebElement.get_attribute`.

        Args:
            name: Name of the attribute to retrieve.

        Returns:
            The value of the attribute.

        Example:
            text_length = target_element.get_dom_attribute("class")
        rL   r8   )r9   r   GET_ELEMENT_ATTRIBUTErN   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 )az  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.

        Args:
            name: Name of the attribute/property to retrieve.

        Returns:
            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-   rD   )r,   rL   attribute_values      r   get_attributezWebElement.get_attribute   s?    6 "J++44((99RSUY[_
 r   c                F    | j                  t        j                        d   S )zReturns whether the element is selected.

        This method is generally used on checkboxes, options in a select
        and radio buttons.

        Example:
            is_selected = element.is_selected()
        r8   )r9   r   IS_ELEMENT_SELECTEDr4   s    r   is_selectedzWebElement.is_selected   s     }}W889'BBr   c                F    | j                  t        j                        d   S )zpReturns whether the element is enabled.

        Example:
            is_enabled = element.is_enabled()
        r8   )r9   r   IS_ELEMENT_ENABLEDr4   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.

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

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

        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"))
        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>   r8   )r-   
_is_remotelistmapr   ra   r   append_uploadtupler9   r   SEND_KEYS_TO_ELEMENTr   )r,   r8   local_filesremote_filesfiles   `    r   	send_keyszWebElement.send_keys   s    4 ;;!!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  Get the shadow root attached to this element if present (Chromium, Firefox, Safari).

        Returns:
            The 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")
        r8   )r9   r   GET_SHADOW_ROOTr4   s    r   shadow_rootzWebElement.shadow_root  s      }}W445g>>r   c                j    t         
t                | j                  j                  dt          d|       S )zvWhether the element is visible to a user.

        Example:
            is_displayed = element.is_displayed()
        z/* isDisplayed */return (rT   )r   r   r-   rD   r4   s    r   is_displayedzWebElement.is_displayed+  s3     !J{{)),EnEUUn*oquvvr   c                    | j                  t        j                  d| gd      d   }t        |d         t        |d         dS )a  Get the element's location on screen after scrolling it into view.

        This may change without warning and scrolls the element into view
        before calculating coordinates for clicking purposes.

        Returns:
            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())rE   argsr8   xyrx   ry   )r9   r   W3C_EXECUTE_SCRIPTround)r,   old_locs     r    location_once_scrolled_into_viewz+WebElement.location_once_scrolled_into_view6  sQ     --&&j
  73<(uWS\/BCCr   c                `    | j                  t        j                        d   }|d   |d   d}|S )zGet the size of the element.

        Returns:
            The width and height of the element.

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

        Args:
            property_name: The name of the CSS property to get the value of.

        Returns:
            The value of the CSS property.

        Example:
            value = element.value_of_css_property("color")
        propertyNamer8   )r9   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 )zGet the location of the element in the renderable canvas.

        Returns:
            The x and y coordinates of the element.

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

        Returns:
            A dictionary with size and location of the element.

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

        Returns:
            The ARIA role of the element.

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

        Returns:
            The ARIA Level of the element.

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

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

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

        Returns:
            The screenshot of the element as binary data.

        Example:
            element_png = element.screenshot_as_png
        ascii)r   r   encoder4   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)a  Save a PNG screenshot of the current element to a file.

        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.

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

        Example:
            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 )zGet the WebDriver instance this element was found from.

        Example:
            element = driver.find_element(By.ID, "foo")
            parent_element = element.parent
        )r*   r4   s    r   r-   zWebElement.parent  s     ||r   c                    | j                   S )a"  Get the 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+   r4   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.

        Args:
            command: The name of the command to _execute as a string.
            params: 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   r9   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.

        Args:
            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.
            value: The locator value to use with the specified `by` strategy.

        Returns:
            The first matching `WebElement` found on the page.

        Example:
            element = driver.find_element(By.ID, "foo")
        usingr8   r8   )r*   locator_converterconvertr9   r   FIND_CHILD_ELEMENTr,   byr8   s      r   find_elementzWebElement.find_element  sG    , 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.

        Args:
            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.
            value: The locator value to use with the specified `by` strategy.

        Returns:
            List of `WebElements` matching locator strategy found on the page.

        Example:
            element = driver.find_elements(By.ID, "foo")
        r   r8   )r*   r   r   r9   r   FIND_CHILD_ELEMENTSr   s      r   find_elementszWebElement.find_elements  sG    , 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   	hexdigestr4   s    r   __hash__zWebElement.__hash__0  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w   r   ro   r8   zUnrecognized command: POSTzCommand not found: POST z.{"status":405,"value":["GET","HEAD","DELETE"]})r   zipfileZipFileZIP_DEFLATEDr   ospathr   closer   getvalue
isinstancera   r   r9   r   UPLOAD_FILEr
   )r,   r   fpzippedcontentes         r   rj   zWebElement._upload3  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   ra   )r   zstr | bool | WebElement | dict)r   z
str | None)r   bool)r8   ra   r   r   )r   r   )r   dict)r   bytesr)   )r   r'   )r   zlist[WebElement])r   r   )*r   r!   r"   r#   r/   r5   propertyr3   r;   r>   rA   rG   rJ   rO   rR   rV   rY   r\   rp   rs   ru   r~   r   r   r   r   r   r   r   r   r   r-   r   r   r   r9   r   IDr   r   r   rj   r$   r   r   r'   r'   :   s   
v ' ' 	D 	D 
@ 
@-o0-_$U" D	CB)
V ? ?$	w D D,  r   	@ 	@ 	E 	E 	F 	F 	B 	B 	D 	D<   
 
A(5 !ee4 a2  "uuD b2Gr   r'   ) 
__future__r   r   r   r   r   abcr   base64r   r   hashlibr   r   ior   selenium.common.exceptionsr	   r
   selenium.webdriver.common.byr   selenium.webdriver.common.utilsr   !selenium.webdriver.remote.commandr   $selenium.webdriver.remote.shadowrootr   r   r   r   r    r'   r$   r   r   <module>r      s]   $ # 	     ) #  N + : 5 ; M	w 	J Jr   