selmate 1.0.1__py3-none-any.whl → 1.0.3__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.
selmate/__init__.py CHANGED
@@ -1,3 +1,5 @@
1
1
  import logging
2
2
 
3
3
  logging.getLogger(__name__).addHandler(logging.NullHandler())
4
+
5
+ __version__ = '1.0.3'
selmate/composites.py CHANGED
@@ -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=10):
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: <{aim_ratio:.2f}>.')
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=10):
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=10, to_x=0):
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: <{aim_ratio:.2f}>.')
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=10, to_x=0):
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 <{len(elements)}> elements as potential popup banners.')
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=<{x}>, y=<{y}>.')
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=<{x}>, y=<{y}>.')
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: <{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: <{suc_step_cnt}>/<{total_step_cnt}>.')
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: <{suc_step_cnt}>/<{total_step_cnt}>.')
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=<{dx}>, dy=<{dy}>.')
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
 
selmate/js_primitives.py CHANGED
@@ -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
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: selmate
3
- Version: 1.0.1
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,13 +1,13 @@
1
- selmate/__init__.py,sha256=MZLaSnD9QbP8pEgsHycojYeOiIu5f7TCSEcd94B3JWQ,81
2
- selmate/composites.py,sha256=gIgFTu0TGExmlS0ptN-NRYPhizf8O8ROZSFkkL3yi8U,25442
1
+ selmate/__init__.py,sha256=JGIwe1YOQRAIogUZwFHjQAQw86d4pIni6coiwFFbgHw,104
2
+ selmate/composites.py,sha256=0CFijQO29VR_YAp26FVd0dSisCa5KYx659ExjjzwsIw,25512
3
3
  selmate/constants.py,sha256=8ZeIZ0v_lWx7_-lN0rYlTNnOCj2zMih1ePQVgtKUsp4,6978
4
4
  selmate/humanity/constants.py,sha256=YYRtMlLapqm1DBCuhdJHFH1Hq4bDSgeXMcpbX-uedoA,234
5
5
  selmate/humanity/latency.py,sha256=xJ2JWtmgxmkqDsTvCMihmuM3KKVP8Crf2YaH2LP7qEs,1263
6
- selmate/js_primitives.py,sha256=4-etOV4ftYwPE9hAOkyS84W19mjzcjYE7enpwdeESEo,6158
6
+ selmate/js_primitives.py,sha256=fJDJdjCHSCNJwdNL0FNABVA0Tt28ESJzaPGG4WO8XJM,6139
7
7
  selmate/safe_exceptions.py,sha256=L2RPD6TSHCIMsyYxiSHbS0EzCaXsyavUi4NvZZqXf7w,1425
8
8
  selmate/selenium_primitives.py,sha256=hKYPFtQCOSuNt3_S1U2Ce9sDhtFe5bhvHwgMChRuUdE,2667
9
9
  selmate/utils.py,sha256=NWImi_DuM9JmsN1E8br2YjCMaWte-mdFbWAPuFHObsY,5012
10
- selmate-1.0.1.dist-info/LICENSE,sha256=7Ivo3S2GrdGr_wc98qnPyERQMV4wxZULNMzgk09S758,1082
11
- selmate-1.0.1.dist-info/METADATA,sha256=gETGVQAXcG2Eb5FvMU5AwIUSNrz1eOALyoSBSu6F1qQ,5512
12
- selmate-1.0.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
13
- selmate-1.0.1.dist-info/RECORD,,
10
+ selmate-1.0.3.dist-info/LICENSE,sha256=7Ivo3S2GrdGr_wc98qnPyERQMV4wxZULNMzgk09S758,1082
11
+ selmate-1.0.3.dist-info/METADATA,sha256=bazXIkI-j4RaDuvbC4nefLxjrXhGFyryl1gsUgTiI_8,5512
12
+ selmate-1.0.3.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
13
+ selmate-1.0.3.dist-info/RECORD,,