zmc
2023-10-12 ed135d79df12a2466b52dae1a82326941211dcc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
U
\±dxBã@sòddlmZddlZddlZddlZddlZddlmZddlm    Z    ddlm
Z
ddl m Z ddlmZddlmZdd    lmZdd
lmZdd lmZdd lmZd dlmZd dlmZdadadd„ZGdd„dedZ Gdd„de ƒZ!dS)é)Ú annotationsN)ÚABCMeta)Ú    b64decode)Ú encodebytes)Úmd5)ÚBytesIO)ÚList)ÚJavascriptException)ÚWebDriverException)ÚBy)Úkeys_to_typingé)ÚCommand)Ú
ShadowRootcCs@d t d¡dd…¡}t |d¡ d¡at |d¡ d¡adS)NÚ.éÿÿÿÿzgetAttribute.jsÚutf8zisDisplayed.js)ÚjoinÚ__name__ÚsplitÚpkgutilÚget_dataÚdecodeÚgetAttribute_jsÚisDisplayed_js)Z_pkg©rú[d:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\selenium/webdriver/remote/webelement.pyÚ_load_js,src@seZdZdZdS)ÚBaseWebElementz…Abstract 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__rrrrr4sr)Ú    metaclassc@seZdZdZddœdd„Zdd„Zeddœd    d
„ƒZeddœd d „ƒZddœd d„Z    dd„Z
ddœdd„Z ddœdd„Z ddœdd„Z ddœdd„Zddœdd„Zddœdd„Zddœdd „Zed!dœd"d#„ƒZddœd$d%„Zed&dœd'd(„ƒZed&dœd)d*„ƒZddœd+d,„Zed&dœd-d.„ƒZed&dœd/d0„ƒZeddœd1d2„ƒZeddœd3d4„ƒZeddœd5d6„ƒZed7dœd8d9„ƒZddœd:d;„Zed<d=„ƒZeddœd>d?„ƒZd@dA„Z dBdC„Z!dQdEdF„Z"e#j$dDfddœdGdH„Z%e#j$dDfdIdœdJdK„Z&dLdœdMdN„Z'dOdP„Z(dDS)RÚ
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.
    ÚNone)ÚreturncCs||_||_dS©N)Ú_parentÚ_id)ÚselfÚparentZid_rrrÚ__init__KszWebElement.__init__c    Cs0dt|ƒj›dt|ƒj›d|jj›d|j›d    S)Nú<rz  (session="z ", element="z")>)Útyperrr'Z
session_idr(©r)rrrÚ__repr__OszWebElement.__repr__ÚstrcCs| tj¡dS)z$This element's ``tagName`` property.Úvalue)Ú_executerZGET_ELEMENT_TAG_NAMEr.rrrÚtag_nameRszWebElement.tag_namecCs| tj¡dS)zThe text of the element.r1)r2rZGET_ELEMENT_TEXTr.rrrÚtextWszWebElement.textcCs| tj¡dS)zClicks the element.N)r2rZ CLICK_ELEMENTr.rrrÚclick\szWebElement.clickcCs8d}z|j ||¡Wntk
r2tdƒ‚YnXdS)zSubmits a form.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)ÚscriptrrrÚsubmit`s ÿ zWebElement.submitcCs| tj¡dS)z-Clears the text if it's a text entry element.N)r2rZ CLEAR_ELEMENTr.rrrÚclearsszWebElement.clearzstr | bool | WebElement | dictcCsBz| tjd|i¡dWStk
r<|j d||¡YSXdS)záGets the given property of the element.
 
        :Args:
            - name - Name of the property to retrieve.
 
        :Usage:
            ::
 
                text_length = target_element.get_property("text_length")
        Únamer1z!return arguments[0][arguments[1]]N)r2rZGET_ELEMENT_PROPERTYr
r*r6©r)r:rrrÚ get_propertyws zWebElement.get_propertycCs| tjd|i¡dS)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.
 
        :Args:
            - name - Name of the attribute to retrieve.
 
        :Usage:
            ::
 
                text_length = target_element.get_dom_attribute("class")
        r:r1)r2rZGET_ELEMENT_ATTRIBUTEr;rrrÚget_dom_attributeˆs zWebElement.get_dom_attributecCs*tdkrtƒ|j dt›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.
 
        :Args:
            - name - Name of the attribute/property to retrieve.
 
        Example::
 
            # Check if the "active" CSS class is applied to an element.
            is_active = "active" in target_element.get_attribute("class")
        Nz/* getAttribute */return (ú).apply(null, arguments);)rrr*r6)r)r:Zattribute_valuerrrÚ get_attribute—s
ÿzWebElement.get_attributeÚboolcCs| tj¡dS)zzReturns whether the element is selected.
 
        Can be used to check if a checkbox or radio button is selected.
        r1)r2rZIS_ELEMENT_SELECTEDr.rrrÚ is_selected·szWebElement.is_selectedcCs| tj¡dS)z'Returns whether the element is enabled.r1)r2rZIS_ELEMENT_ENABLEDr.rrrÚ
is_enabled¾szWebElement.is_enabledcs†ˆjjr`tt‡fdd„d tt|ƒ¡ d¡ƒƒ}d|kr`g}|D]}| ˆ |¡¡q@d |¡}ˆ     t
j d t |ƒ¡t |ƒdœ¡dS)a2Simulates typing into the element.
 
        :Args:
            - value - A string for typing, or setting form fields.  For setting
              file inputs, this could be a local file path.
 
        Use this to send simple key events or to fill out form fields::
 
            form_textfield = driver.find_element(By.NAME, 'username')
            form_textfield.send_keys("admin")
 
        This can also be used to set file inputs.
 
        ::
 
            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"))
        csˆjj t|ƒ¡Sr&)r*Z file_detectorZ is_local_filer0)Z keys_to_sendr.rrÚ<lambda>Ýóz&WebElement.send_keys.<locals>.<lambda>ÚÚ
N)r4r1) r*Z
_is_remoteÚlistÚmaprr0rÚappendÚ_uploadr2rZSEND_KEYS_TO_ELEMENTr )r)r1Z local_filesZ remote_filesÚfilerr.rÚ    send_keysÂs 
þÿ
ÿzWebElement.send_keysrcCsdt|jjd d¡dƒ}|jjd ¡dks6tdƒ‚|dksTtd|jjd›ƒ‚| tj¡d    S)
aLReturns a shadow root of the element if there is one or an error.
        Only works from Chromium 96 and Firefox 96 onwards. Previous versions
        of browsers will throw an assertion exception.
 
        :Returns:
          - ShadowRoot object or
          - NoSuchShadowRoot - if no shadow root was attached to element
        ZbrowserVersionrrZ browserNameZsafariz@This only currently works in Firefox and Chromium based browsersé_zUPlease use Firefox or Chromium based browsers with version 96 or later. Version used r1)    Úintr'ZcapsrÚlowerÚAssertionErrorr2rZGET_SHADOW_ROOT)r)Zbrowser_main_versionrrrÚ shadow_rootës
ÿþÿþzWebElement.shadow_rootcCs$tdkrtƒ|j dt›d|¡S)z)Whether the element is visible to a user.Nz/* isDisplayed */return (r>)rrr*r6r.rrrÚ is_displayedÿszWebElement.is_displayedÚdictcCs4| tjd|gdœ¡d}t|dƒt|dƒdœS)aETHIS 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 the top lefthand corner location on the screen, or
        ``None`` if the element is not visible.
        zNarguments[0].scrollIntoView(true); return arguments[0].getBoundingClientRect())r7Úargsr1ÚxÚy©rUrV)r2rZW3C_EXECUTE_SCRIPTÚround)r)Úold_locrrrÚ location_once_scrolled_into_views    þþúz+WebElement.location_once_scrolled_into_viewcCs&| tj¡d}|d|ddœ}|S)zThe size of the element.r1ÚheightÚwidth)r[r\©r2rÚGET_ELEMENT_RECT)r)ÚsizeZnew_sizerrrr_szWebElement.sizecCs| tjd|i¡dS)zThe value of a CSS property.Z propertyNamer1)r2rZ!GET_ELEMENT_VALUE_OF_CSS_PROPERTY)r)Z property_namerrrÚvalue_of_css_propertysz WebElement.value_of_css_propertycCs.| tj¡d}t|dƒt|dƒdœ}|S)z5The location of the element in the renderable canvas.r1rUrVrW)r2rr^rX)r)rYZnew_locrrrÚlocation#szWebElement.locationcCs| tj¡dS)z7A dictionary with the size and location of the element.r1r]r.rrrÚrect*szWebElement.rectcCs| tj¡dS)z1Returns the ARIA role of the current web element.r1)r2rZGET_ELEMENT_ARIA_ROLEr.rrrÚ    aria_role/szWebElement.aria_rolecCs| tj¡dS)z1Returns the ARIA Level of the current webelement.r1)r2rZGET_ELEMENT_ARIA_LABELr.rrrÚaccessible_name4szWebElement.accessible_namecCs| tj¡dS)z¯Gets the screenshot of the current element as a base64 encoded
        string.
 
        :Usage:
            ::
 
                img_b64 = element.screenshot_as_base64
        r1)r2rZELEMENT_SCREENSHOTr.rrrÚscreenshot_as_base649s
zWebElement.screenshot_as_base64ÚbytescCst|j d¡ƒS)zžGets the screenshot of the current element as a binary data.
 
        :Usage:
            ::
 
                element_png = element.screenshot_as_png
        Úascii)rreÚencoder.rrrÚscreenshot_as_pngEs    zWebElement.screenshot_as_pngc    Csn| ¡ d¡st dt¡|j}zDz$t|dƒ}| |¡W5QRXWntk
r`YW¢
dSXW5~XdS)aš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.
 
        :Args:
         - filename: The full path you wish to save your screenshot to. This
           should end with a `.png` extension.
 
        :Usage:
            ::
 
                element.screenshot('/Screenshots/foo.png')
        z.pngz^name used for saved screenshot does not match file type. It should end with a `.png` extensionÚwbFT)    rOÚendswithÚwarningsÚwarnÚ UserWarningriÚopenÚwriteÚOSError)r)ÚfilenameZpngÚfrrrÚ
screenshotPsþ zWebElement.screenshotcCs|jS)zQInternal reference to the WebDriver instance this element was found
        from.)r'r.rrrr*mszWebElement.parentcCs|jS)aInternal 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 ``==``::
 
            if element1 == element2:
                print("These 2 are equal")
        )r(r.rrrÚidss
z WebElement.idcCst|dƒo|j|jkS)Nru)Úhasattrr(ru©r)ÚelementrrrÚ__eq__szWebElement.__eq__cCs | |¡ Sr&)ryrwrrrÚ__ne__‚szWebElement.__ne__NcCs |si}|j|d<|j ||¡S)a9Executes 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.
        ru)r(r'Úexecute)r)ÚcommandÚparamsrrrr2†s
 
zWebElement._executecCsn|tjkrtj}d|›d}n8|tjkr:tj}d|›}n|tjkrVtj}d|›d}| tj||dœ¡dS)z³Find an element given a By strategy and locator.
 
        :Usage:
            ::
 
                element = element.find_element(By.ID, 'foo')
 
        :rtype: WebElement
        ú[id="ú"]rú[name="©Zusingr1r1)r ÚIDÚ CSS_SELECTORÚ
CLASS_NAMEÚNAMEr2rZFIND_CHILD_ELEMENT©r)Zbyr1rrrÚ find_element•s
 
 
 
 zWebElement.find_elementzList[WebElement]cCsn|tjkrtj}d|›d}n8|tjkr:tj}d|›}n|tjkrVtj}d|›d}| tj||dœ¡dS)zÂFind elements given a By strategy and locator.
 
        :Usage:
            ::
 
                element = element.find_elements(By.CLASS_NAME, 'foo')
 
        :rtype: list of WebElement
        r~rrr€rr1)r r‚rƒr„r…r2rZFIND_CHILD_ELEMENTSr†rrrÚ find_elements«s
 
 
 
 zWebElement.find_elementsrNcCstt|j d¡ƒ ¡dƒS)Núutf-8é)rNÚmd5_hashr(rhÚ    hexdigestr.rrrÚ__hash__ÁszWebElement.__hash__c
Csàtƒ}t |dtj¡}| |tj |¡d¡| ¡t    | 
¡ƒ}t |t ƒsV|  d¡}z| tjd|i¡dWStk
rÚ}zNdt |ƒkr˜|WY¢8Sdt |ƒkr°|WY¢ Sdt |ƒkrÈ|WY¢S‚W5d}~XYnXdS)    NÚwr r‰rKr1zUnrecognized command: POSTzCommand not found: POST z.{"status":405,"value":["GET","HEAD","DELETE"]})rÚzipfileÚZipFileÚ ZIP_DEFLATEDrpÚosÚpathrÚcloserÚgetvalueÚ
isinstancer0rr2rZ UPLOAD_FILEr
)r)rrÚfpZzippedÚcontentÚerrrrJÄs" 
 
      zWebElement._upload)N))rrr r!r+r/Úpropertyr3r4r5r8r9r<r=r?rArBrLrQrRrZr_r`rarbrcrdrerirtr*ruryrzr2r r‚r‡rˆrrJrrrrr#>s`  ) 
 
 
r#)"Ú
__future__rr’rrlrÚabcrÚbase64rrÚhashlibrr‹ÚiorÚtypingrZselenium.common.exceptionsr    r
Zselenium.webdriver.common.byr Zselenium.webdriver.common.utilsr r|rZ
shadowrootrrrrrr#rrrrÚ<module>s*