utils-seleniumxp 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- utils_seleniumxp/SeleniumPythonUtils.ini +80 -0
- utils_seleniumxp/__init__.py +135 -0
- utils_seleniumxp/eventfiring_addon.py +453 -0
- utils_seleniumxp/eventlistener.py +276 -0
- utils_seleniumxp/locatorutils.py +162 -0
- utils_seleniumxp/sessionhandling.py +965 -0
- utils_seleniumxp/version.py +55 -0
- utils_seleniumxp/webdriver_addon.py +1112 -0
- utils_seleniumxp/webelement_addon.py +438 -0
- utils_seleniumxp-1.0.0.dist-info/METADATA +96 -0
- utils_seleniumxp-1.0.0.dist-info/RECORD +14 -0
- utils_seleniumxp-1.0.0.dist-info/WHEEL +4 -0
- utils_seleniumxp-1.0.0.dist-info/licenses/AUTHORS.md +3 -0
- utils_seleniumxp-1.0.0.dist-info/licenses/LICENSE.txt +33 -0
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
# Selenium webdriver utilities - XP version
|
|
2
|
+
# webelement - additional functionalities
|
|
3
|
+
# wrapper class not possible as WebElement class is referred to by general webdriver class
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
module with webelement class extensions
|
|
7
|
+
|
|
8
|
+
Webelement extensions include:
|
|
9
|
+
- more convenient access as select object
|
|
10
|
+
- various scrolling
|
|
11
|
+
- retrieval of XPATH of an element
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# ruff and mypy per file settings
|
|
16
|
+
#
|
|
17
|
+
# empty lines
|
|
18
|
+
# ruff: noqa: E302, E303
|
|
19
|
+
# naming conventions
|
|
20
|
+
# ruff: noqa: N801, N802, N803, N806, N812, N813, N815, N816, N818, N999
|
|
21
|
+
# boolean-type arguments
|
|
22
|
+
# ruff: noqa: FBT001, FBT002
|
|
23
|
+
# others
|
|
24
|
+
# ruff: noqa: B010, E305, E501
|
|
25
|
+
#
|
|
26
|
+
# disable mypy errors
|
|
27
|
+
# mypy: disable-error-code = "no-any-return, attr-defined"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# fmt: off
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# TODO Dev:
|
|
35
|
+
# - extension for mixin classes / own routines
|
|
36
|
+
# - click_and_wait (possibly include scroll_into_view) ?
|
|
37
|
+
|
|
38
|
+
# TODO Test:
|
|
39
|
+
# - n. a.
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
import time
|
|
44
|
+
|
|
45
|
+
import parsel
|
|
46
|
+
import cssify
|
|
47
|
+
|
|
48
|
+
import utils_seleniumxp
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
# block direct calling
|
|
53
|
+
# __all__ = []
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# asselect wrapper for webelement - provides more OOic approach on SELECT-webelement
|
|
58
|
+
|
|
59
|
+
# pseudo-wrapper for select webelement - implement asselect method to avoid Select(webdriver.find_element(...))
|
|
60
|
+
def asselect(webelement: utils_seleniumxp._WebElement) -> utils_seleniumxp.Select:
|
|
61
|
+
"""
|
|
62
|
+
asselect - provide direct access to select object to a SELECT-tag
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
webelement (utils_seleniumxp._WebElement): webelement
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
utils_seleniumxp.Select: Selenium select object
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
if webelement.tag_name.upper() == "SELECT":
|
|
72
|
+
return utils_seleniumxp.Select(webelement)
|
|
73
|
+
else:
|
|
74
|
+
err_msg = "WebElement is not a SELECT element."
|
|
75
|
+
raise utils_seleniumxp.ErrorUtilsSelenium(err_msg)
|
|
76
|
+
|
|
77
|
+
def as_select(webelement: utils_seleniumxp._WebElement) -> utils_seleniumxp.Select:
|
|
78
|
+
"""
|
|
79
|
+
as_select - provide direct access to select object to a SELECT-tag (alternative caller to asselect)
|
|
80
|
+
"""
|
|
81
|
+
return asselect(webelement)
|
|
82
|
+
|
|
83
|
+
# no mixin-object for WebElement -> direct settattr
|
|
84
|
+
setattr(utils_seleniumxp._WebElement, "asselect", asselect)
|
|
85
|
+
setattr(utils_seleniumxp._WebElement, "as_select", asselect)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
# webelement - hover over element
|
|
89
|
+
|
|
90
|
+
# hover over element
|
|
91
|
+
def hover_over(webelement: utils_seleniumxp._WebElement) -> None:
|
|
92
|
+
"""
|
|
93
|
+
hover_over - action chain to hover over element
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
webelement (utils_seleniumxp._WebElement): webelement
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
utils_seleniumxp.WebDriver.ActionChains(webelement.parent).move_to_element(webelement).perform()
|
|
100
|
+
|
|
101
|
+
# no mixin-object for WebElement -> direct settattr
|
|
102
|
+
setattr(utils_seleniumxp._WebElement, "hover_over", hover_over)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
# webelement - scroll into view or viewport / scroll into view and click
|
|
106
|
+
|
|
107
|
+
# scroll into view
|
|
108
|
+
def scroll_into_view(
|
|
109
|
+
webelement: utils_seleniumxp._WebElement, offset_pixels: int = 0, align_to_top: bool = False
|
|
110
|
+
) -> None:
|
|
111
|
+
"""
|
|
112
|
+
scroll_into_view - scroll webelement into view
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
webelement (utils_seleniumxp._WebElement): webelement
|
|
116
|
+
offset_pixels (int, optional): vertical pixel offset. Defaults to 0.
|
|
117
|
+
align_to_top (bool, optional): flag for alignment to top of page. Defaults to False.
|
|
118
|
+
"""
|
|
119
|
+
|
|
120
|
+
webelement.parent.execute_script("arguments[0].scrollIntoView(arguments[1]);", webelement, align_to_top)
|
|
121
|
+
# compensate for the header
|
|
122
|
+
# unfortunately subsequent scripts seem to interfere with previous script if no wait
|
|
123
|
+
if offset_pixels != 0:
|
|
124
|
+
time.sleep(0.5)
|
|
125
|
+
webelement.parent.execute_script(f"window.scrollBy(0, {offset_pixels});")
|
|
126
|
+
else:
|
|
127
|
+
time.sleep(0.5)
|
|
128
|
+
|
|
129
|
+
# scroll into view and click
|
|
130
|
+
def scroll_into_view_and_click(
|
|
131
|
+
webelement: utils_seleniumxp._WebElement, offset_pixels: int = 0, align_to_top: bool = False
|
|
132
|
+
) -> None:
|
|
133
|
+
"""
|
|
134
|
+
scroll_into_view_and_click - scroll webelement into view and click
|
|
135
|
+
|
|
136
|
+
Args:
|
|
137
|
+
webelement (utils_seleniumxp._WebElement): webelement
|
|
138
|
+
offset_pixels (int, optional): vertical pixel offset. Defaults to 0.
|
|
139
|
+
align_to_top (bool, optional): flag for alignment to top of page. Defaults to False.
|
|
140
|
+
"""
|
|
141
|
+
|
|
142
|
+
webelement.scroll_into_view(offset_pixels, align_to_top)
|
|
143
|
+
webelement.click()
|
|
144
|
+
|
|
145
|
+
# scroll into middle of viewport
|
|
146
|
+
def scroll_into_viewportmid(webelement: utils_seleniumxp._WebElement) -> None:
|
|
147
|
+
"""
|
|
148
|
+
scroll_into_viewportmid - scroll webelement into mid of viewport
|
|
149
|
+
|
|
150
|
+
Args:
|
|
151
|
+
webelement (utils_seleniumxp._WebElement): webelement
|
|
152
|
+
"""
|
|
153
|
+
|
|
154
|
+
script = (
|
|
155
|
+
"var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);"
|
|
156
|
+
"var elementTop = arguments[0].getBoundingClientRect().top;"
|
|
157
|
+
"window.scrollBy(0, elementTop-(viewPortHeight/2));"
|
|
158
|
+
)
|
|
159
|
+
webelement.parent.execute_script(script, webelement)
|
|
160
|
+
time.sleep(0.5)
|
|
161
|
+
|
|
162
|
+
# no mixin-object for WebElement -> direct settattr
|
|
163
|
+
setattr(utils_seleniumxp._WebElement, "scroll_into_view", scroll_into_view)
|
|
164
|
+
setattr(utils_seleniumxp._WebElement, "scroll_into_view_and_click", scroll_into_view_and_click)
|
|
165
|
+
setattr(utils_seleniumxp._WebElement, "scroll_into_viewportmid", scroll_into_viewportmid)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
# webelement - get xpath and CSS selector
|
|
169
|
+
|
|
170
|
+
# script for getting element index to retrieve tag
|
|
171
|
+
script_get_tag_idx = """
|
|
172
|
+
function get_tag_idx(element) {
|
|
173
|
+
var ix = 0;
|
|
174
|
+
var siblings = element.parentElement.children;
|
|
175
|
+
for (var i = 0; i < siblings.length; i++) {
|
|
176
|
+
var sibling = siblings[i];
|
|
177
|
+
if (sibling === element)
|
|
178
|
+
return (ix+1);
|
|
179
|
+
if (sibling.tagName === element.tagName)
|
|
180
|
+
ix++;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return get_tag_idx(arguments[0]);
|
|
184
|
+
"""
|
|
185
|
+
|
|
186
|
+
# get simple XPath via loop
|
|
187
|
+
# idea and input:
|
|
188
|
+
# - https://stackoverflow.com/questions/2661818/javascript-get-xpath-of-a-node
|
|
189
|
+
# - https://stackoverflow.com/questions/5913927/get-child-node-index/42692428
|
|
190
|
+
def get_xpath(webelement: utils_seleniumxp._WebElement, use_id: bool = True) -> str:
|
|
191
|
+
"""
|
|
192
|
+
get_xpath - get XPATH for webelement
|
|
193
|
+
|
|
194
|
+
Args:
|
|
195
|
+
webelement (utils_seleniumxp._WebElement): webelement
|
|
196
|
+
use_id (bool, optional): flag if ID attribute should be used. Defaults to True.
|
|
197
|
+
|
|
198
|
+
Returns:
|
|
199
|
+
str: XPATH to webelement
|
|
200
|
+
"""
|
|
201
|
+
|
|
202
|
+
parsedhtml = parsel.Selector(text=webelement.parent.page_source)
|
|
203
|
+
xpath = ""
|
|
204
|
+
|
|
205
|
+
while "/body" not in xpath:
|
|
206
|
+
|
|
207
|
+
webelement_id = webelement.get_attribute("id")
|
|
208
|
+
webelement_tag = webelement.tag_name.lower()
|
|
209
|
+
|
|
210
|
+
if webelement_id is not None and webelement_id != "" and webelement_tag != "body":
|
|
211
|
+
# use id
|
|
212
|
+
xpath_section = f"/{webelement_tag}[@id='{webelement_id}']"
|
|
213
|
+
if use_id and len(parsedhtml.xpath("/" + xpath_section).getall()) == 1:
|
|
214
|
+
xpath = "/" + xpath_section + xpath
|
|
215
|
+
break
|
|
216
|
+
else:
|
|
217
|
+
xpath = xpath_section + xpath
|
|
218
|
+
elif webelement_tag == "body":
|
|
219
|
+
# body element reached
|
|
220
|
+
xpath = "/html/body" + xpath
|
|
221
|
+
break
|
|
222
|
+
else:
|
|
223
|
+
# get element index (two versions possible - a) generalized n-th child or b) n-th child with specific tag-name
|
|
224
|
+
# idx = webelement.parent.execute_script("return Array.from(arguments[0].parentNode.children).indexOf(arguments[0])", webelement)
|
|
225
|
+
# xpath_section = f"/*[{idx + 1}]"
|
|
226
|
+
idx = webelement.parent.execute_script(script_get_tag_idx, webelement)
|
|
227
|
+
xpath_section = f"/{webelement_tag}[{idx}]"
|
|
228
|
+
xpath = xpath_section + xpath
|
|
229
|
+
webelement = webelement.find_element(utils_seleniumxp.By.XPATH, "./parent::*")
|
|
230
|
+
|
|
231
|
+
return xpath
|
|
232
|
+
|
|
233
|
+
# get simple XPath via recursive call
|
|
234
|
+
def get_xpath_recursive(webelement: utils_seleniumxp._WebElement, parsedhtml=None, use_id: bool = True) -> str:
|
|
235
|
+
"""
|
|
236
|
+
get_xpath_recursive - get XPATH for webelement
|
|
237
|
+
|
|
238
|
+
Args:
|
|
239
|
+
webelement (utils_seleniumxp._WebElement): webelement
|
|
240
|
+
parsedhtml (_type_, optional): parsel selector object. Defaults to None.
|
|
241
|
+
use_id (bool, optional): flag if ID attribute should be used. Defaults to True.
|
|
242
|
+
|
|
243
|
+
Returns:
|
|
244
|
+
str: XPATH to webelement
|
|
245
|
+
"""
|
|
246
|
+
|
|
247
|
+
if webelement is None:
|
|
248
|
+
return ""
|
|
249
|
+
|
|
250
|
+
if parsedhtml is None:
|
|
251
|
+
parsedhtml = parsel.Selector(text=webelement.parent.page_source)
|
|
252
|
+
|
|
253
|
+
webelement_id = webelement.get_attribute("id")
|
|
254
|
+
webelement_tag = webelement.tag_name.lower()
|
|
255
|
+
|
|
256
|
+
if webelement_id is not None and webelement_id != "" and webelement_tag != "body":
|
|
257
|
+
# use id
|
|
258
|
+
xpath_section = f"/{webelement_tag}[@id='{webelement_id}']"
|
|
259
|
+
if use_id and len(parsedhtml.xpath("/" + xpath_section).getall()) == 1:
|
|
260
|
+
return "/" + xpath_section
|
|
261
|
+
elif webelement_tag == "body":
|
|
262
|
+
# body element reached
|
|
263
|
+
return "/html/body"
|
|
264
|
+
else:
|
|
265
|
+
# get element index (two versions possible - a) generalized n-th child or b) n-th child with specific tag-name)
|
|
266
|
+
# idx = webelement.parent.execute_script("return Array.from(arguments[0].parentNode.children).indexOf(arguments[0])", webelement)
|
|
267
|
+
# xpath_section = f"/*[{idx + 1}]"
|
|
268
|
+
idx = webelement.parent.execute_script(script_get_tag_idx, webelement)
|
|
269
|
+
xpath_section = f"/{webelement_tag}[{idx}]"
|
|
270
|
+
|
|
271
|
+
return get_xpath_recursive(
|
|
272
|
+
webelement.find_element(utils_seleniumxp.By.XPATH, "./parent::*"), parsedhtml, use_id
|
|
273
|
+
) + xpath_section
|
|
274
|
+
|
|
275
|
+
# no mixin-object for WebElement -> direct settattr
|
|
276
|
+
setattr(utils_seleniumxp._WebElement, "get_xpath", get_xpath)
|
|
277
|
+
setattr(utils_seleniumxp._WebElement, "get_xpath_recursive", get_xpath_recursive)
|
|
278
|
+
|
|
279
|
+
# get simple CSS selector
|
|
280
|
+
def get_css_selector_from_xpath(webelement: utils_seleniumxp._WebElement, use_id: bool = False) -> str:
|
|
281
|
+
"""
|
|
282
|
+
get_css_selector_from_xpath - get CSS selector for webelement by transforming XPATH
|
|
283
|
+
|
|
284
|
+
Args:
|
|
285
|
+
webelement (utils_seleniumxp._WebElement): webelement
|
|
286
|
+
use_id (bool, optional): flag if ID attribute should be used. Defaults to False.
|
|
287
|
+
|
|
288
|
+
Returns:
|
|
289
|
+
str: CSS selector to webelement
|
|
290
|
+
"""
|
|
291
|
+
|
|
292
|
+
xpath = webelement.get_xpath(use_id)
|
|
293
|
+
return cssify.cssify(xpath)
|
|
294
|
+
|
|
295
|
+
def get_css_selector(webelement: utils_seleniumxp._WebElement) -> str:
|
|
296
|
+
"""
|
|
297
|
+
get_css_selector - get CSS selector for webelement
|
|
298
|
+
|
|
299
|
+
Args:
|
|
300
|
+
webelement (utils_seleniumxp._WebElement): webelement
|
|
301
|
+
|
|
302
|
+
Returns:
|
|
303
|
+
str: CSS selector to webelement
|
|
304
|
+
"""
|
|
305
|
+
|
|
306
|
+
css_selector: list[str] = []
|
|
307
|
+
element = webelement
|
|
308
|
+
|
|
309
|
+
while element.tag_name.lower() != 'html':
|
|
310
|
+
|
|
311
|
+
tag = element.tag_name.lower()
|
|
312
|
+
parent = element.find_element(utils_seleniumxp.By.XPATH, "..")
|
|
313
|
+
siblings = parent.find_elements(utils_seleniumxp.By.XPATH, f"./{tag}")
|
|
314
|
+
|
|
315
|
+
if len(siblings) == 1:
|
|
316
|
+
css_selector.insert(0, tag)
|
|
317
|
+
else:
|
|
318
|
+
index = None
|
|
319
|
+
for i, sibling in enumerate(siblings, start=1):
|
|
320
|
+
if sibling._id == element._id:
|
|
321
|
+
index = i
|
|
322
|
+
break
|
|
323
|
+
css_selector.insert(0, f"{tag}:nth-of-type({index})")
|
|
324
|
+
|
|
325
|
+
element = parent
|
|
326
|
+
|
|
327
|
+
css_selector.insert(0, "html")
|
|
328
|
+
return " > ".join(css_selector)
|
|
329
|
+
|
|
330
|
+
# no mixin-object for WebElement -> direct settattr
|
|
331
|
+
setattr(utils_seleniumxp._WebElement, "get_css_selector_from_xpath", get_css_selector)
|
|
332
|
+
setattr(utils_seleniumxp._WebElement, "get_css_selector", get_css_selector)
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
# webelement - check if element is present
|
|
336
|
+
|
|
337
|
+
# check if child webelement is present
|
|
338
|
+
# w/o optimization pretty slow, optimization uses XPATH to webelement
|
|
339
|
+
def is_present(
|
|
340
|
+
webelement: utils_seleniumxp._WebElement, by: utils_seleniumxp.By, value: str, use_parsel: bool = True
|
|
341
|
+
) -> bool:
|
|
342
|
+
"""
|
|
343
|
+
is_present - check if child webelement is present
|
|
344
|
+
|
|
345
|
+
Args:
|
|
346
|
+
webelement (utils_seleniumxp._WebElement): webelement
|
|
347
|
+
by (utils_seleniumxp.By): locator type
|
|
348
|
+
value (str): locator value
|
|
349
|
+
use_parsel (bool, optional): flag to use parsel. Defaults to True
|
|
350
|
+
|
|
351
|
+
Returns:
|
|
352
|
+
bool: flag if element is present or not
|
|
353
|
+
"""
|
|
354
|
+
|
|
355
|
+
if use_parsel and by in {utils_seleniumxp.By.XPATH, utils_seleniumxp.By.CSS_SELECTOR}:
|
|
356
|
+
xpath = webelement.get_xpath()
|
|
357
|
+
value = xpath + "/" + value if by == utils_seleniumxp.By.XPATH else cssify.cssify(xpath) + " > " + value
|
|
358
|
+
parsedhtml = utils_seleniumxp.parselSelectorExtension(text=webelement.parent.page_source)
|
|
359
|
+
return len(parsedhtml.css_or_xpath(utils_seleniumxp.SeleniumLocator(by, value)).getall()) > 0
|
|
360
|
+
else:
|
|
361
|
+
try:
|
|
362
|
+
webelement.find_element(by, value)
|
|
363
|
+
except Exception:
|
|
364
|
+
return False
|
|
365
|
+
else:
|
|
366
|
+
return True
|
|
367
|
+
|
|
368
|
+
def is_element_present(webelement: utils_seleniumxp._WebElement, by: utils_seleniumxp.By, value: str, use_parsel: bool = True) -> bool:
|
|
369
|
+
"""
|
|
370
|
+
is_element_present - check if child webelement is present (alternative caller to is_present)
|
|
371
|
+
"""
|
|
372
|
+
return is_present(webelement, by, value, use_parsel)
|
|
373
|
+
|
|
374
|
+
# no mixin-object for WebElement -> direct settattr
|
|
375
|
+
setattr(utils_seleniumxp._WebElement, "is_present", is_present)
|
|
376
|
+
setattr(utils_seleniumxp._WebElement, "is_element_present", is_present)
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
# webelement - check for overlap, get overlapping element
|
|
380
|
+
# inspired by https://stackoverflow.com/questions/49921128/selenium-cant-click-element-because-other-element-obscures-it/72361846#72361846
|
|
381
|
+
|
|
382
|
+
# check for overlap
|
|
383
|
+
def is_overlapped(webelement: utils_seleniumxp._WebElement) -> bool:
|
|
384
|
+
"""
|
|
385
|
+
is_overlapped - check if element is overlapped
|
|
386
|
+
|
|
387
|
+
Args:
|
|
388
|
+
webelement (utils_seleniumxp._WebElement): webelement
|
|
389
|
+
|
|
390
|
+
Return:
|
|
391
|
+
bool: element is overlapped
|
|
392
|
+
"""
|
|
393
|
+
|
|
394
|
+
check_element = get_overlapping_element(webelement)
|
|
395
|
+
return not (check_element is None or check_element == webelement)
|
|
396
|
+
|
|
397
|
+
# no mixin-object for WebElement -> direct settattr
|
|
398
|
+
setattr(utils_seleniumxp._WebElement, "is_overlapped", is_overlapped)
|
|
399
|
+
|
|
400
|
+
# get overlapping element
|
|
401
|
+
def get_overlapping_element(webelement: utils_seleniumxp._WebElement) -> utils_seleniumxp._WebElement:
|
|
402
|
+
"""
|
|
403
|
+
get_overlapping_element - get overlapping element
|
|
404
|
+
|
|
405
|
+
Args:
|
|
406
|
+
webelement (utils_seleniumxp._WebElement): webelement
|
|
407
|
+
|
|
408
|
+
Return:
|
|
409
|
+
utils_seleniumxp._WebElement: overlapping webelement
|
|
410
|
+
"""
|
|
411
|
+
|
|
412
|
+
rect = webelement.rect
|
|
413
|
+
result = webelement.parent.execute_script("return document.elementFromPoint(arguments[0], arguments[1]);", rect['x'] + rect['width'] // 2, rect['y'] + rect['height'] // 2)
|
|
414
|
+
if result == webelement:
|
|
415
|
+
result = None
|
|
416
|
+
return result
|
|
417
|
+
|
|
418
|
+
# no mixin-object for WebElement -> direct settattr
|
|
419
|
+
setattr(utils_seleniumxp._WebElement, "get_overlapping_element", get_overlapping_element)
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
# webelement - clear & send_keys
|
|
423
|
+
|
|
424
|
+
# clear element and send keys
|
|
425
|
+
def clear_and_send_keys(webelement: utils_seleniumxp._WebElement, value: str) -> None:
|
|
426
|
+
"""
|
|
427
|
+
clear_and_send_keys - clear element and send keys to it (combine simple calls)
|
|
428
|
+
|
|
429
|
+
Args:
|
|
430
|
+
webelement (utils_seleniumxp._WebElement): webelement
|
|
431
|
+
value (str): value for send_keys
|
|
432
|
+
"""
|
|
433
|
+
|
|
434
|
+
webelement.clear()
|
|
435
|
+
webelement.send_keys(value)
|
|
436
|
+
|
|
437
|
+
# no mixin-object for WebElement -> direct settattr
|
|
438
|
+
setattr(utils_seleniumxp._WebElement, "clear_and_send_keys", clear_and_send_keys)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: utils-seleniumxp
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Package with utilities and functional extensions for Selenium webdriver Python language bindings
|
|
5
|
+
Project-URL: Documentation, https://dornech.github.io/utils-seleniumxp
|
|
6
|
+
Project-URL: Source, https://github.com/dornech/utils-seleniumxp
|
|
7
|
+
Project-URL: Tracker, https://github.com/dornech/utils-seleniumxp/issues
|
|
8
|
+
Project-URL: Sponsor, https://github.com/sponsors/dornech
|
|
9
|
+
Author-email: dornech <dornech@gmx.de>
|
|
10
|
+
License: GPL-3.0-only
|
|
11
|
+
License-File: AUTHORS.md
|
|
12
|
+
License-File: LICENSE.txt
|
|
13
|
+
Keywords: Chrome,FireFox,Selenium,close popup,event-firing webdriver,factory function,parsel,webdriver
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Requires-Dist: cssify
|
|
23
|
+
Requires-Dist: parsel
|
|
24
|
+
Requires-Dist: psutil
|
|
25
|
+
Requires-Dist: requests
|
|
26
|
+
Requires-Dist: selenium
|
|
27
|
+
Requires-Dist: selenium-requests
|
|
28
|
+
Requires-Dist: stealthenium
|
|
29
|
+
Requires-Dist: utils-mystuff
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# SeleniumXP utilities for Python
|
|
33
|
+
|
|
34
|
+
Package with utilities and functional extensions for Selenium webdriver Python language bindings
|
|
35
|
+
|
|
36
|
+
## Features
|
|
37
|
+
|
|
38
|
+
The package consist of various helpers and extensions to the Selenium webdriver:
|
|
39
|
+
|
|
40
|
+
- module for session handling especially a custom factory function to initialize a webdriver object
|
|
41
|
+
- module with additional methods for the webdriver class
|
|
42
|
+
- module with convenience functions for locators
|
|
43
|
+
- module with additional methods for the webelement class
|
|
44
|
+
- an extended event-firing webdriver and an extended listener abstract base class
|
|
45
|
+
- a sample event listener implementation based on the extended abstract base class
|
|
46
|
+
|
|
47
|
+
Different from other packages extending the Selenium webdriver class does not work with
|
|
48
|
+
wrapping the original webdriver but providing a mixin class or alternatively directly setting
|
|
49
|
+
additional methods via 'setattr' in the original webdriver class. This is done and controlled
|
|
50
|
+
via a pretty versatile custom factory function initializing the webdriver.
|
|
51
|
+
|
|
52
|
+
The webelement extension are done via setattr only. Implementing a mixin class would require
|
|
53
|
+
to modify webdriver methods to return the new class with the mixin. So benefit of the
|
|
54
|
+
settattr approach is that extending the webelement class is independend from changes to the
|
|
55
|
+
webdriver class.
|
|
56
|
+
|
|
57
|
+
Note: as I am coming from camel case notation I was struggling a little bit with the Python naming conventions.
|
|
58
|
+
However, for publishing I tried to increase compliance with Python naming conventions and added snake case
|
|
59
|
+
method stubs (at least for most important subroutines) as a compromise.
|
|
60
|
+
|
|
61
|
+
## Development
|
|
62
|
+
|
|
63
|
+
To set up [hatch] and [pre-commit] for the first time:
|
|
64
|
+
|
|
65
|
+
1. install [hatch] globally, e.g. with [pipx], i.e. `pipx install hatch`,
|
|
66
|
+
2. make sure `pre-commit` is installed globally, e.g. with `pipx install pre-commit`.
|
|
67
|
+
|
|
68
|
+
A special feature that makes hatch very different from other familiar tools is that you almost never
|
|
69
|
+
activate, or enter, an environment. Instead, you use `hatch run env_name:command` and the `default` environment
|
|
70
|
+
is assumed for a command if there is no colon found. Thus you must always define your environment in a declarative
|
|
71
|
+
way and hatch makes sure that the environment reflects your declaration by updating it whenever you issue
|
|
72
|
+
a `hatch run ...`. This helps with reproducability and avoids forgetting to specify dependencies since the
|
|
73
|
+
hatch workflow is to specify everything directly in [pyproject.toml](pyproject.toml). Only in rare cases, you
|
|
74
|
+
will use `hatch shell` to enter the `default` environment, which is similar to what you may know from other tools.
|
|
75
|
+
|
|
76
|
+
To get you started, use `hatch run test:cov` or `hatch run test:no-cov` to run the unitest with or without coverage reports,
|
|
77
|
+
respectively. Use `hatch run lint:all` to run all kinds of typing and linting checks. Try to automatically fix linting
|
|
78
|
+
problems with `hatch run lint:fix` and use `hatch run docs:serve` to build and serve your documentation.
|
|
79
|
+
You can also easily define your own environments and commands. Check out the environment setup of hatch
|
|
80
|
+
in [pyproject.toml](pyproject.toml) for more commands as well as the package, build and tool configuration.
|
|
81
|
+
|
|
82
|
+
To support versioning and changelog generation please refer to the toolchain selected during package
|
|
83
|
+
generation (see also `pyproject.toml`). If not deselected, the toolchain includes a [pre-commit] hook
|
|
84
|
+
for linting commit messages to ensure commit messages are compliant with the conventional commit format and
|
|
85
|
+
support an automated changelog generation.
|
|
86
|
+
|
|
87
|
+
## Credits
|
|
88
|
+
|
|
89
|
+
This package was created with [The Hatchlor Enhanced] project template. This template is based on [The Hatchlor]
|
|
90
|
+
but was substantially improved.
|
|
91
|
+
|
|
92
|
+
[The Hatchlor Enhanced]: https://github.com/dornech/the-hatchlor-enhanced
|
|
93
|
+
[The Hatchlor]: https://github.com/florianwilhelm/the-hatchlor
|
|
94
|
+
[pipx]: https://pypa.github.io/pipx/
|
|
95
|
+
[hatch]: https://hatch.pypa.io/
|
|
96
|
+
[pre-commit]: https://pre-commit.com/
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
utils_seleniumxp/SeleniumPythonUtils.ini,sha256=puaSw0ZPRDSvT4RvNIMbGRREHYBTK4d_Tea2jG-U9qE,2145
|
|
2
|
+
utils_seleniumxp/__init__.py,sha256=w7p5N70KOKwBBjmD9rYjOAQpNS_Ad-PBYNUdILt4VAU,6207
|
|
3
|
+
utils_seleniumxp/eventfiring_addon.py,sha256=Ym6vXYMVppdvvl1ekP8eZXrYHbEqq3tRQEsoqq8QACM,16139
|
|
4
|
+
utils_seleniumxp/eventlistener.py,sha256=9nILtosC2r8eUr2JCeRYA2zJs8o6kiQTghUYOtOhs_4,10572
|
|
5
|
+
utils_seleniumxp/locatorutils.py,sha256=gEOJdyJiwZD-Yf3hpW4neCDj-RnJdMmeNp3ou6VntY0,4759
|
|
6
|
+
utils_seleniumxp/sessionhandling.py,sha256=Rc7kuLUgNuWtGd0IQTVFoWT6KbIXLSLuN4vLS7gAdus,42666
|
|
7
|
+
utils_seleniumxp/version.py,sha256=lALyRABJtfZHDW1KiyUImeIS5FyoyNJCjqlDmKGpMCw,1893
|
|
8
|
+
utils_seleniumxp/webdriver_addon.py,sha256=lGDTBKaqi5MgtsCSi1CHc-hAMqrmi6IO3HqfBzx3C74,49620
|
|
9
|
+
utils_seleniumxp/webelement_addon.py,sha256=TxsjanfkdD_S5PBLJC0QiwjfApT-Th6oX7TFC11XjHk,14995
|
|
10
|
+
utils_seleniumxp-1.0.0.dist-info/METADATA,sha256=qu9Eda9awqXiB4w_f2iwBc3gwu-3AyD-HEYCtgfI4O8,5195
|
|
11
|
+
utils_seleniumxp-1.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
12
|
+
utils_seleniumxp-1.0.0.dist-info/licenses/AUTHORS.md,sha256=hjIl3u05KlQzMtYDikuvIzEeFR2s3QcpW6xvF1DYq9o,56
|
|
13
|
+
utils_seleniumxp-1.0.0.dist-info/licenses/LICENSE.txt,sha256=vuY1ZqTmNcbXSwaSHJl97l7_PlDwdZJdV5krga6Rjww,1609
|
|
14
|
+
utils_seleniumxp-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
GNU GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Package with utilities and functional extensions for Selenium webdriver
|
|
5
|
+
Python language bindings
|
|
6
|
+
Copyright (C) 2024 dornech
|
|
7
|
+
|
|
8
|
+
This program is free software: you can redistribute it and/or modify
|
|
9
|
+
it under the terms of the GNU General Public License as published by
|
|
10
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
(at your option) any later version.
|
|
12
|
+
|
|
13
|
+
This program is distributed in the hope that it will be useful,
|
|
14
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
GNU General Public License for more details.
|
|
17
|
+
|
|
18
|
+
You should have received a copy of the GNU General Public License
|
|
19
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
|
|
21
|
+
Also add information on how to contact you by electronic and paper mail.
|
|
22
|
+
|
|
23
|
+
You should also get your employer (if you work as a programmer) or school,
|
|
24
|
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
25
|
+
For more information on this, and how to apply and follow the GNU GPL, see
|
|
26
|
+
<http://www.gnu.org/licenses/>.
|
|
27
|
+
|
|
28
|
+
The GNU General Public License does not permit incorporating your program
|
|
29
|
+
into proprietary programs. If your program is a subroutine library, you
|
|
30
|
+
may consider it more useful to permit linking proprietary applications with
|
|
31
|
+
the library. If this is what you want to do, use the GNU Lesser General
|
|
32
|
+
Public License instead of this License. But first, please read
|
|
33
|
+
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|