selmate 1.0.1__tar.gz → 1.0.3__tar.gz
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.
- {selmate-1.0.1 → selmate-1.0.3}/PKG-INFO +1 -1
- {selmate-1.0.1 → selmate-1.0.3}/pyproject.toml +1 -1
- {selmate-1.0.1 → selmate-1.0.3}/selmate/__init__.py +2 -0
- {selmate-1.0.1 → selmate-1.0.3}/selmate/composites.py +16 -15
- {selmate-1.0.1 → selmate-1.0.3}/selmate/js_primitives.py +0 -1
- {selmate-1.0.1 → selmate-1.0.3}/LICENSE +0 -0
- {selmate-1.0.1 → selmate-1.0.3}/README.md +0 -0
- {selmate-1.0.1 → selmate-1.0.3}/selmate/constants.py +0 -0
- {selmate-1.0.1 → selmate-1.0.3}/selmate/humanity/constants.py +0 -0
- {selmate-1.0.1 → selmate-1.0.3}/selmate/humanity/latency.py +0 -0
- {selmate-1.0.1 → selmate-1.0.3}/selmate/safe_exceptions.py +0 -0
- {selmate-1.0.1 → selmate-1.0.3}/selmate/selenium_primitives.py +0 -0
- {selmate-1.0.1 → selmate-1.0.3}/selmate/utils.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: selmate
|
3
|
-
Version: 1.0.
|
3
|
+
Version: 1.0.3
|
4
4
|
Summary: A utility library for Selenium WebDriver to enable human-like interactions, robust exception handling, and web automation tasks like popup handling and URL normalization.
|
5
5
|
License: MIT License
|
6
6
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "selmate"
|
3
|
-
version = "1.0.
|
3
|
+
version = "1.0.3"
|
4
4
|
description = "A utility library for Selenium WebDriver to enable human-like interactions, robust exception handling, and web automation tasks like popup handling and URL normalization."
|
5
5
|
authors = [{ name = "FINWAX", email = "waxbid@gmail.com" }]
|
6
6
|
license = { file = "LICENSE" }
|
@@ -31,11 +31,12 @@ from selmate.utils import is_confirmation_text, norm_string, latency_time, norma
|
|
31
31
|
logger = logging.getLogger(__name__)
|
32
32
|
|
33
33
|
|
34
|
-
def wandering_between_elements(elements, driver, max_moves=0):
|
34
|
+
def wandering_between_elements(elements, driver, max_moves=0, mouse_step=10.0):
|
35
35
|
"""Simulates mouse wandering between pairs of elements.
|
36
36
|
:param elements: List of elements to wander between.
|
37
37
|
:param driver: The Selenium WebDriver instance.
|
38
38
|
:param max_moves: Maximum number of moves to perform.
|
39
|
+
:param mouse_step: Amount of pixels for one scroll.
|
39
40
|
:return: Tuple of the last element and number of moves made.
|
40
41
|
"""
|
41
42
|
move_cnt = 0
|
@@ -47,7 +48,7 @@ def wandering_between_elements(elements, driver, max_moves=0):
|
|
47
48
|
if el2 is None or not element_displayed_enabled(el2):
|
48
49
|
continue
|
49
50
|
|
50
|
-
wander_between_2_elements(el1, el2, driver, 0.01)
|
51
|
+
wander_between_2_elements(el1, el2, driver, mouse_step, 0.01)
|
51
52
|
human_observe_view_latency()
|
52
53
|
|
53
54
|
move_cnt += 1
|
@@ -140,7 +141,7 @@ def get_element_url(element: WebElement):
|
|
140
141
|
return None
|
141
142
|
|
142
143
|
|
143
|
-
def selenium_random_vertical_scroll(driver, from_ratio=-0.5, to_ratio=0.5, step=
|
144
|
+
def selenium_random_vertical_scroll(driver, from_ratio=-0.5, to_ratio=0.5, step=30):
|
144
145
|
"""Performs a random vertical scroll within a ratio range.
|
145
146
|
:param driver: The Selenium WebDriver instance.
|
146
147
|
:param from_ratio: Minimum scroll ratio.
|
@@ -149,13 +150,13 @@ def selenium_random_vertical_scroll(driver, from_ratio=-0.5, to_ratio=0.5, step=
|
|
149
150
|
"""
|
150
151
|
doc_height = driver.execute_script("return document.body.scrollHeight")
|
151
152
|
aim_ratio = random.uniform(from_ratio, to_ratio)
|
152
|
-
logger.debug(f'Aim ratio for random human scroll:
|
153
|
+
logger.debug(f'Aim ratio for random selenium human scroll: {aim_ratio:.2f}.')
|
153
154
|
on_delta = int(aim_ratio * doc_height)
|
154
155
|
|
155
156
|
selenium_human_vertical_scroll(on_delta, driver, step)
|
156
157
|
|
157
158
|
|
158
|
-
def selenium_human_vertical_scroll(y_delta, driver, step=
|
159
|
+
def selenium_human_vertical_scroll(y_delta, driver, step=30):
|
159
160
|
"""Performs a smooth vertical scroll by a specified delta.
|
160
161
|
:param y_delta: The vertical distance to scroll.
|
161
162
|
:param driver: The Selenium WebDriver instance.
|
@@ -170,7 +171,7 @@ def selenium_human_vertical_scroll(y_delta, driver, step=10):
|
|
170
171
|
actions.perform()
|
171
172
|
|
172
173
|
|
173
|
-
def js_random_human_scroll(driver, from_ratio=0.25, to_ratio=1.0, step=
|
174
|
+
def js_random_human_scroll(driver, from_ratio=0.25, to_ratio=1.0, step=30, to_x=0):
|
174
175
|
"""Performs a random vertical scroll using JavaScript.
|
175
176
|
:param driver: The Selenium WebDriver instance.
|
176
177
|
:param from_ratio: Minimum scroll ratio.
|
@@ -180,13 +181,13 @@ def js_random_human_scroll(driver, from_ratio=0.25, to_ratio=1.0, step=10, to_x=
|
|
180
181
|
"""
|
181
182
|
doc_height = driver.execute_script("return document.body.scrollHeight")
|
182
183
|
aim_ratio = random.uniform(from_ratio, to_ratio)
|
183
|
-
logger.debug(f'Aim ratio for random human scroll:
|
184
|
+
logger.debug(f'Aim ratio for random js human scroll: {aim_ratio:.2f}.')
|
184
185
|
to_y = aim_ratio * doc_height
|
185
186
|
|
186
187
|
js_human_vertical_scroll(to_y, driver, step, to_x)
|
187
188
|
|
188
189
|
|
189
|
-
def js_human_vertical_scroll(to_y, driver, step=
|
190
|
+
def js_human_vertical_scroll(to_y, driver, step=30, to_x=0):
|
190
191
|
"""Performs a smooth vertical scroll to a y-coordinate using JavaScript.
|
191
192
|
:param to_y: Target y-coordinate.
|
192
193
|
:param driver: The Selenium WebDriver instance.
|
@@ -301,7 +302,7 @@ def bypass_popup_banners(
|
|
301
302
|
:param allow_removing_when_closing: Whether to allow element removal.
|
302
303
|
"""
|
303
304
|
elements = find_top_available_elements(By.CSS_SELECTOR, 'div', driver)
|
304
|
-
logger.debug(f'Found
|
305
|
+
logger.debug(f'Found {len(elements)} elements as potential popup banners.')
|
305
306
|
cnt = 0
|
306
307
|
suc_cnt = 0
|
307
308
|
for el in elements:
|
@@ -343,7 +344,7 @@ def close_element(element, driver, allow_removing=True, close_btn_text_threshold
|
|
343
344
|
rect = element.rect
|
344
345
|
move_radius = 2 * max(rect['width'], rect['height'])
|
345
346
|
x, y = selenium_element_center(element)
|
346
|
-
logger.debug(f'Close button center coordinates: x
|
347
|
+
logger.debug(f'Close button center coordinates: x={x}, y={y}.')
|
347
348
|
|
348
349
|
if complex_click(close_btn, driver):
|
349
350
|
logger.debug('Successfully clicked the close button in the element.')
|
@@ -394,7 +395,7 @@ def accept_popup_banner(banner, driver):
|
|
394
395
|
rect = btn.rect
|
395
396
|
move_radius = 2 * max(rect['width'], rect['height'])
|
396
397
|
x, y = selenium_element_center(btn)
|
397
|
-
logger.debug(f'Confirmation button center coordinates: x
|
398
|
+
logger.debug(f'Confirmation button center coordinates: x={x}, y={y}.')
|
398
399
|
|
399
400
|
if selenium_scroll_to_element(btn, driver):
|
400
401
|
human_observe_view_latency()
|
@@ -465,10 +466,10 @@ def random_mouse_move_in_vicinity(radius, driver, x1=0, y1=0, mouse_step=10.0, e
|
|
465
466
|
|
466
467
|
actions = ActionChains(driver)
|
467
468
|
path = generate_curved_path(x1, y1, x2, y2, mouse_step)
|
468
|
-
logger.debug(f'Generated mouse path:
|
469
|
+
logger.debug(f'Generated mouse path: {path}.')
|
469
470
|
suc_step_cnt, total_step_cnt = move_mouse_by_path(path, actions, x1, y1, eps)
|
470
471
|
|
471
|
-
logger.debug(f'Mouse movements in vicinity:
|
472
|
+
logger.debug(f'Mouse movements in vicinity: {suc_step_cnt}/{total_step_cnt}.')
|
472
473
|
|
473
474
|
|
474
475
|
def find_top_available_elements(by, value, driver, skip_under_one=True, sort_z_children_desc=True) -> List[WebElement]:
|
@@ -547,7 +548,7 @@ def wander_between_2_elements(
|
|
547
548
|
|
548
549
|
actions.move_to_element(to_element).perform()
|
549
550
|
|
550
|
-
logger.debug(f'Mouse movements while wandering between elements:
|
551
|
+
logger.debug(f'Mouse movements while wandering between elements: {suc_step_cnt}/{total_step_cnt}.')
|
551
552
|
return True
|
552
553
|
|
553
554
|
|
@@ -573,7 +574,7 @@ def move_mouse_by_path(path, actions, x1=0, y1=0, eps=0.01):
|
|
573
574
|
total_step_cnt += 1
|
574
575
|
|
575
576
|
dx, dy = x - prev_x, y - prev_y
|
576
|
-
logger.debug(f'Mouse moving: dx
|
577
|
+
logger.debug(f'Mouse moving: dx={dx}, dy={dy}.')
|
577
578
|
if abs(dx) < eps and abs(dy) < eps:
|
578
579
|
continue
|
579
580
|
|
@@ -70,7 +70,6 @@ def js_smooth_scroll(to_x, to_y, driver):
|
|
70
70
|
:param to_x: Target x-coordinate.
|
71
71
|
:param to_y: Target y-coordinate.
|
72
72
|
:param driver: The Selenium WebDriver instance.
|
73
|
-
:return: None
|
74
73
|
"""
|
75
74
|
driver.execute_script(f"window.scrollTo({to_x}, {to_y}, {{behaviour: 'smooth'}});")
|
76
75
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|