utils-seleniumxp 1.1.0__tar.gz → 1.2.0__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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: utils-seleniumxp
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: Package with utilities and functional extensions for Selenium webdriver Python language bindings
5
5
  Project-URL: Documentation, https://dornech.github.io/utils-seleniumxp
6
6
  Project-URL: Source, https://github.com/dornech/utils-seleniumxp
@@ -10,23 +10,25 @@ Author-email: dornech <dornech@gmx.de>
10
10
  License: GPL-3.0-only
11
11
  License-File: AUTHORS.md
12
12
  License-File: LICENSE.txt
13
- Keywords: Chrome,FireFox,Selenium,close popup,event-firing webdriver,factory function,parsel,webdriver
13
+ Keywords: Chrome,FireFox,Selenium,close popup,event-firing webdriver,factory function,parsel,requests,stealth-selenium,waitless,webdriver
14
14
  Classifier: Programming Language :: Python
15
- Classifier: Programming Language :: Python :: 3.10
16
15
  Classifier: Programming Language :: Python :: 3.11
17
16
  Classifier: Programming Language :: Python :: 3.12
18
17
  Classifier: Programming Language :: Python :: 3.13
19
18
  Classifier: Programming Language :: Python :: 3.14
20
19
  Classifier: Programming Language :: Python :: Implementation :: CPython
21
- Requires-Python: >=3.10
20
+ Requires-Python: >=3.11
22
21
  Requires-Dist: cssify
22
+ Requires-Dist: hatchling
23
23
  Requires-Dist: parsel
24
24
  Requires-Dist: psutil
25
25
  Requires-Dist: requests
26
+ Requires-Dist: selenium-autowait
26
27
  Requires-Dist: selenium-requests
27
- Requires-Dist: selenium~=4.33.0
28
+ Requires-Dist: selenium>=4.33.0
28
29
  Requires-Dist: stealthenium>=1.1.1
29
30
  Requires-Dist: utils-mystuff
31
+ Requires-Dist: waitless
30
32
  Description-Content-Type: text/markdown
31
33
 
32
34
  # SeleniumXP utilities for Python
@@ -15,13 +15,14 @@ build-backend = "hatchling.build"
15
15
  name = "utils-seleniumxp"
16
16
  description = "Package with utilities and functional extensions for Selenium webdriver Python language bindings"
17
17
  readme = "README.md"
18
- requires-python = ">=3.10"
18
+ requires-python = ">=3.11"
19
19
  # only license identifier from https://spdx.org/licenses/ are allowed
20
20
  license = { text = "GPL-3.0-only" }
21
21
  # keywords for easier look-up on PyPI
22
22
  keywords = [
23
23
  "Selenium", "webdriver", "Chrome", "FireFox",
24
- "factory function", "event-firing webdriver", "parsel", "close popup"
24
+ "factory function", "event-firing webdriver", "close popup",
25
+ "parsel", "requests", "stealth-selenium", "waitless"
25
26
  ]
26
27
  authors = [
27
28
  { name = "dornech", email = "dornech@gmx.de" },
@@ -29,7 +30,6 @@ authors = [
29
30
  # options under https://pypi.org/classifiers/
30
31
  classifiers = [
31
32
  "Programming Language :: Python",
32
- "Programming Language :: Python :: 3.10",
33
33
  "Programming Language :: Python :: 3.11",
34
34
  "Programming Language :: Python :: 3.12",
35
35
  "Programming Language :: Python :: 3.13",
@@ -39,13 +39,16 @@ classifiers = [
39
39
  # direct dependencies of this package, installed when users `pip install utils-seleniumxp` later.
40
40
  dependencies = [
41
41
  "cssify",
42
+ "hatchling",
42
43
  "parsel",
43
44
  "psutil",
44
45
  "requests",
45
- "selenium~=4.33.0",
46
+ "selenium>=4.33.0",
47
+ "selenium-autowait",
46
48
  "selenium-requests",
47
49
  "stealthenium>=1.1.1",
48
- "utils_mystuff"
50
+ "utils-mystuff",
51
+ "waitless",
49
52
  ]
50
53
  dynamic = ["version"]
51
54
 
@@ -93,7 +96,7 @@ exclude = [
93
96
  [tool.commitizen]
94
97
  name = "cz_customize"
95
98
  version_scheme = "pep440"
96
- version = "1.1.0"
99
+ version = "1.2.0"
97
100
  version_files = ["pyproject.toml:version"]
98
101
  tag_format = "v$version"
99
102
  # retry_after_failure = false
@@ -120,8 +123,8 @@ bump_map = {"feat" = "MINOR", "fix" = "PATCH", "BREAKING CHANGE" = "MAJOR"}
120
123
  # with Initial Commit in changelog
121
124
  commit_parser ="^(?P<change_type>[Ii]nitial [Cc]ommit|feat|fix|refactor|perf|docs|style|test|chore|build|ci|revert|BREAKING CHANGE)(\\((?P<scope>[^)]+)\\))?(:\\s(?P<message>.*))?"
122
125
  changelog_pattern = "^([Ii]nitial [Cc]ommit|feat|fix|docs|style|refactor|perf|test|chore|build|ci|revert|BREAKING CHANGE).*"
123
- change_type_map = { feat = "Features", fix = "Bug fixes", refactor = "Refactoring", perf = "performance improvements", docs = "Documentation", style = "Code style", test = "Testing", chore = "Chores", build = "Build system", ci = "Continuous Integration" }
124
- change_type_order = ["BREAKING CHANGE", "feat", "fix", "refactor", "perf", "docs", "style", "test", "chore", "build", "ci"]
126
+ change_type_map = { feat = "Features", fix = "Bug fixes", refactor = "Code refactoring", perf = "Performance improvements", docs = "Documentation", style = "Code style", test = "Testing", chore = "Chores", build = "Build system", ci = "Continuous Integration" }
127
+ change_type_order = ["BREAKING CHANGE", "Features", "Bug fixes", "Code refactoring", "Performance improvements", "Documentation", "Code style", "Testing", "Chore", "Build System", "Continuous Integration", "Initial Commit"]
125
128
 
126
129
 
127
130
  ##################
@@ -140,7 +143,7 @@ ignore-args = false
140
143
  ignore-kwargs = false
141
144
  ignore-no-params = true
142
145
  ignore_typechecker= false
143
- # disable = []
146
+ disable = ["SIG305", "SIG306"]
144
147
  # target = []
145
148
 
146
149
  [tool.ruff]
@@ -151,8 +154,9 @@ include = [
151
154
  "src/**/*.py",
152
155
  "src/**/*.pyi",
153
156
  "tests/**/*.py",
154
- "tests/**/*.pyi"
157
+ "tests/**/*.pyi",
155
158
  ]
159
+ output-prefer-rule-codes = true
156
160
 
157
161
  [tool.ruff.lint]
158
162
  preview = true # preview features & checks, use with caution
@@ -247,6 +251,16 @@ warn_unused_ignores = true
247
251
  warn_return_any = true
248
252
  warn_unused_configs = true
249
253
 
254
+ [tool.deptry]
255
+ known_first_party = ["utils_seleniumxp"]
256
+ exclude = ["docs", "tests"]
257
+ ignore_notebooks = true
258
+ github_output = true
259
+ github_warning_errors = ["DEP003"]
260
+
261
+ [tool.deptry.package_module_name_map]
262
+ selenium-requests = "seleniumrequests"
263
+
250
264
  [tool.cruft]
251
265
  skip = ["README.md", "CHANGELOG.MD", "src/", "tests/", "docs/", "notebooks/"]
252
266
 
@@ -256,6 +270,10 @@ addopts = "-ra -q --doctest-glob='*.md'"
256
270
  testpaths = [
257
271
  "tests",
258
272
  ]
273
+ markers = [
274
+ "integration: integration test cases",
275
+ "local: test cases not suitable for CI",
276
+ ]
259
277
 
260
278
  [tool.coverage.run]
261
279
  branch = true
@@ -302,20 +320,21 @@ dependencies = [
302
320
  ]
303
321
  # installer = "pip"
304
322
 
305
- # Hatch default test environment for "hatch test" (also used in GitAction)
323
+ # Hatch default test environment for "hatch test" (also used in GitHub Action)
324
+ # do not define scripts [tool.hatch.envs.hatch-test.scripts] without taking over hatch standard scripts!!!
306
325
  [tool.hatch.envs.hatch-test]
307
326
  dependencies = [
308
327
  "pip",
309
328
  "coverage-enable-subprocess==1.0",
310
- "coverage[toml]~=7.4",
311
- "pytest~=8.1",
312
- "pytest-mock~=3.12",
313
- "pytest-randomly~=3.15",
314
- "pytest-rerunfailures~=14.0",
315
- "pytest-xdist[psutil]~=3.5",
329
+ "coverage[toml]>=7.4",
330
+ "pytest>=8.1",
331
+ "pytest-mock>=3.12",
332
+ "pytest-randomly>=3.15",
333
+ "pytest-rerunfailures>=14.0",
334
+ "pytest-xdist[psutil]>=3.5",
316
335
  ]
317
336
 
318
- # Test environment with test-only dependencies (do not mix up with default hatch-test environment "hatch-test" !)
337
+ # Hatch local testing environment with test-only dependencies (do not mix up with default hatch-test environment "hatch-test" !)
319
338
  [tool.hatch.envs.test]
320
339
  dependencies = [
321
340
  # required test dependencies
@@ -332,28 +351,30 @@ dependencies = [
332
351
  cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=src/utils_seleniumxp --cov=tests {args}"
333
352
  no-cov = "cov --no-cov {args}"
334
353
  debug = "cov --no-cov -s --pdb --pdbcls=IPython.core.debugger:Pdb {args}"
354
+ test_not_local_only = "run pytest -m 'not local'"
355
+ test_local_only = "run pytest -m 'local'"
335
356
 
336
- # Hatch testing environment matrix for various Python versions replacing the functionality of tox
357
+ # Hatch local testing environment matrix for various Python versions replacing the functionality of tox
337
358
  [[tool.hatch.envs.test.matrix]]
338
359
  template = ["test"]
339
- python = ["3.10", "3.11", "3.12", "3.13", "3.14"]
360
+ python = ["3.11", "3.12", "3.13", "3.14"]
340
361
 
341
362
  # Hatch default linting environment for "hatch fmt"
342
363
  [tool.hatch.envs.hatch-static-analysis]
343
364
  dependencies = [
344
365
  "pip",
345
- "mypy==1.16.0",
346
- "ruff==0.11.12",
366
+ "mypy==2.3.0",
367
+ "ruff==0.16.2",
347
368
  ]
348
369
 
349
- # Hatch Linting environment for GitAction
370
+ # Hatch Linting environment for GitHub Action
350
371
  [tool.hatch.envs.lint]
351
372
  template = "lint" # don't inherit from default!
352
373
  dependencies = [
353
374
  "pip",
354
- "mypy==1.16.0",
355
- "ruff==0.11.12",
356
- "docsig==0.71.0",
375
+ "mypy==2.3.0",
376
+ "ruff==0.16.2",
377
+ "docsig==0.94.0",
357
378
  ]
358
379
  [tool.hatch.envs.lint.scripts]
359
380
  typing = [
@@ -34,7 +34,7 @@ provided for enabling a direct download, disabling browser notifications or opti
34
34
 
35
35
  The webelement extension are done via setattr only. Implementing a mixin class would require
36
36
  to modify webdriver methods to return the new class with the mixin. So benefit of the
37
- settattr approach is that extending the webelement class is independend from changes to the
37
+ settattr approach is that extending the webelement class is independent from changes to the
38
38
  webdriver class.
39
39
 
40
40
  The package also provides an extended event-firing webdriver class.
@@ -70,13 +70,20 @@ from utils_seleniumxp.version import __version__
70
70
  # package: import <selenium.xxx> as <SeleniumBinding short name>
71
71
  # use: from UtilsSeleniumXP import <SeleniumBinding short name>
72
72
 
73
- from selenium import webdriver as WebDriver
73
+ # from selenium import webdriver as WebDriver
74
+ from selenium.webdriver.chrome.webdriver import WebDriver as Chrome
75
+ from selenium.webdriver.chrome.options import Options as ChromeOptions
76
+ from selenium.webdriver.firefox.webdriver import WebDriver as Firefox
77
+ from selenium.webdriver.firefox.options import Options as FirefoxOptions
78
+ # from selenium.webdriver.common.webdriver import LocalWebDriver as _LocalWebDriver
79
+ from selenium.webdriver.remote.webdriver import WebDriver as WebDriver
74
80
  from selenium.webdriver.remote.webdriver import WebDriver as _RemoteWebDriver
75
81
  from selenium.webdriver.remote.webelement import WebElement as _WebElement
76
82
  from selenium.webdriver.remote.shadowroot import ShadowRoot as _ShadowRoot
77
83
  from selenium.webdriver.remote.switch_to import SwitchTo as _SwitchTo
78
84
  from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
79
85
  from selenium.webdriver.common.alert import Alert
86
+ from selenium.webdriver.common.action_chains import ActionChains
80
87
  from selenium.webdriver.common.by import By
81
88
  from selenium.webdriver.common.keys import Keys
82
89
  from selenium.webdriver.support.select import Select
@@ -15,7 +15,7 @@ module providing event firing and listening - additional functionalities compare
15
15
  # boolean-type arguments
16
16
  # ruff: noqa: FBT001, FBT002
17
17
  # others
18
- # ruff: noqa: B006, E301, PLR0904, PLR0917, SIM102
18
+ # ruff: noqa: B006, E301, PLR0904, PLR0917, RUF105, SIM102
19
19
  #
20
20
  # disable mypy errors
21
21
  # - mypy error "Returning Any from function ..."
@@ -17,7 +17,7 @@ the Selenium project including not covered standard functions
17
17
  # boolean-type arguments
18
18
  # ruff: noqa: FBT001, FBT002
19
19
  # others
20
- # ruff: noqa: B006, PLR0904, PLR5501, PLR6301
20
+ # ruff: noqa: B006, PLR0904, PLR5501, PLR6301, RUF105
21
21
 
22
22
  # fmt: off
23
23
 
@@ -15,7 +15,7 @@ module providing Selenium locator tools
15
15
  # boolean-type arguments
16
16
  # ruff: noqa: FBT001, FBT002
17
17
  # others
18
- # ruff: noqa: B006, TID252
18
+ # ruff: noqa: B006, RUF105, TID252
19
19
  #
20
20
  # disable mypy errors
21
21
  # mypy: disable-error-code = "attr-defined, no-any-return"
@@ -23,10 +23,10 @@ Currently full support is implemented for Chrome and Firefox only.
23
23
  # boolean-type arguments
24
24
  # ruff: noqa: FBT001, FBT002
25
25
  # others
26
- # ruff: noqa: B006, B008, B010, E501, PLC0415, PLR0914, PLR0917, PLR1702, PLR2004, RUF022, S101, S110, S113, SIM102
26
+ # ruff: noqa: B006, B008, B010, E501, PLC0415, PLR0914, PLR0917, PLR1702, PLR2004, RUF022, RUF050, RUF105, S101, S110, S113, SIM102
27
27
  #
28
28
  # disable mypy errors
29
- # mypy: disable-error-code = "attr-defined, arg-type, call-overload, no-any-return, unused-ignore"
29
+ # mypy: disable-error-code = "arg-type, attr-defined, call-overload, no-any-return, unused-ignore"
30
30
 
31
31
  # fmt: off
32
32
 
@@ -36,12 +36,8 @@ Currently full support is implemented for Chrome and Firefox only.
36
36
  # - decorator to check browser type for various functions to simplify code ?
37
37
  # - use user profiles ?
38
38
  # - additional parameters in INI file Selenium.ini
39
- # - implicitlywait
40
- # - flag for stealth mode ?
41
- # - flag for optimized scraping mode ?
42
39
  # - combine with a wrapper for config
43
40
  # https://github.com/MikeFez/BrowserWrapper/blob/main/BrowserWrapper/browserwrapper.py ?
44
- # - include/activate webdriver management ?
45
41
  # - Firefox improvements (but worth the effort as Chrome is faster anyway and currently causes problems?)
46
42
  # - Firefox eventfiring webdriver: problem with hanging Firefox and hanging processes when checked last time
47
43
  # - re-connect mechanism as for Chrome, seems to be supported from Selenium4 onwards
@@ -61,7 +57,7 @@ Currently full support is implemented for Chrome and Firefox only.
61
57
 
62
58
 
63
59
 
64
- from typing import Any
60
+ from typing import Any, Literal
65
61
  from collections.abc import Callable
66
62
 
67
63
  import os
@@ -74,7 +70,7 @@ import inspect
74
70
  import atexit
75
71
  import contextlib
76
72
  import psutil
77
- import signal
73
+ # import signal
78
74
  import zipfile
79
75
 
80
76
  import requests
@@ -94,7 +90,7 @@ __all__ = [
94
90
  'disablenotifications',
95
91
  'connectChrome', 'connect_chrome',
96
92
  'checkDebugport', 'check_debugport',
97
- 'getChromeUserDataDir', 'get_Chrome_userdata_dir'
93
+ 'getChromeUserDataDir', 'get_chrome_userdata_dir'
98
94
  ]
99
95
 
100
96
 
@@ -107,6 +103,10 @@ stealthmode_default = False
107
103
  # switch optimized scraping
108
104
  optimizedscraping_default = False
109
105
 
106
+ # switch and mode for optimized wait
107
+ smartwait_default = True
108
+ smartwait_mode: Literal["autowait", "waitless"] = "waitless"
109
+
110
110
 
111
111
 
112
112
  # initialize selenium driver including starting new browser instance
@@ -120,11 +120,12 @@ def init_webdriver(
120
120
  maxpageload: int = 30,
121
121
  mixin: bool = utils_seleniumxp.mixinactive,
122
122
  eventlistener: utils_seleniumxp.eventfiring_addon.AbstractEventListenerExtended | None = None,
123
+ smartwait: bool = smartwait_default,
123
124
  stealthmode: bool = stealthmode_default,
124
125
  optimizedscraping: bool = optimizedscraping_default,
125
126
  URL: str = "about:blank",
126
127
  alt_cls_webdriverwrapper: type[utils_seleniumxp._RemoteWebDriver] | None = None,
127
- alt_cls_options: type[utils_seleniumxp.WebDriver.ChromeOptions] | type[utils_seleniumxp.WebDriver.FirefoxOptions] | None = None
128
+ alt_cls_options: type[utils_seleniumxp.ChromeOptions] | type[utils_seleniumxp.FirefoxOptions] | None = None
128
129
  ) -> utils_seleniumxp._RemoteWebDriver:
129
130
  """
130
131
  init_webdriver - initialize Selenium webdriver session
@@ -134,7 +135,7 @@ def init_webdriver(
134
135
  to the webdriver binary and extension files. A profile section defines the browser, the driver path,
135
136
  the extension path and the extensions to be loaded. Config file interpolation might be used for paths.
136
137
  Per driver a driver specific section is required defining at least the file for the extensions.
137
- Currently settings beyond paths and extensions are not supported.
138
+ Currently, settings beyond paths and extensions are not supported.
138
139
 
139
140
  settings:
140
141
  settings is provided as a list of callables. The callables must return a browser-specific settings data object.
@@ -154,11 +155,12 @@ def init_webdriver(
154
155
  maxpageload (int, optional): max pageload time. Defaults to 20.
155
156
  mixin (bool, optional): flag to switch between mixin and setattr mode. Defaults to utils_seleniumxp.mixinactive.
156
157
  eventlistener (Optional[utils_seleniumxp.eventfiring_addon.AbstractEventListenerExtended], optional): eventlistener object to activate eventfiring mode. Defaults to None.
158
+ smartwait (bool, optional): flag to activate "smart" wait
157
159
  stealthmode (bool, optional): flag to control selenium_stealth mode. Defaults to stealthmode_default.
158
160
  optimizedscraping (bool, optional): flag to control optimized settings for scraping (no pictures etc.). Defaults to optimizedscraping_default.
159
161
  URL (str, optional): start URL. Defaults to "about:blank".
160
162
  alt_cls_webdriverwrapper (Optional[utils_seleniumxp.WebDriver], optional): optional base webdriver class. Defaults to None.
161
- alt_cls_options (Union[utils_seleniumxp.WebDriver.ChromeOptions, utils_seleniumxp.WebDriver.FirefoxOptions, None], optional): optional browser options class. Defaults to None.
163
+ alt_cls_options (Union[utils_seleniumxp.ChromeOptions, utils_seleniumxp.FirefoxOptions, None], optional): optional browser options class. Defaults to None.
162
164
 
163
165
  Returns:
164
166
  utils_seleniumxp.WebDriver: webdriver object
@@ -305,8 +307,8 @@ def init_webdriver(
305
307
  if browser == "chrome":
306
308
 
307
309
  # set options object - some wrappers define own options class
308
- browsersettings = utils_seleniumxp.WebDriver.ChromeOptions() if alt_cls_options is None else alt_cls_options()
309
- assert isinstance(browsersettings, utils_seleniumxp.WebDriver.ChromeOptions)
310
+ browsersettings = utils_seleniumxp.ChromeOptions() if alt_cls_options is None else alt_cls_options()
311
+ assert isinstance(browsersettings, utils_seleniumxp.ChromeOptions)
310
312
 
311
313
  # options / preferences
312
314
  prefsdict: dict = {}
@@ -324,15 +326,21 @@ def init_webdriver(
324
326
  # settings for Chrome
325
327
  browsersettings.add_argument("--disable-features=UserAgentClientHint,OptimizationGuideModelDownloading,OptimizationHintsFetching,OptimizationTargetPrediction,OptimizationHints")
326
328
  browsersettings.add_argument("--disable-search-engine-choice-screen")
329
+ # avoid problem with undetected-chromedriver
330
+ # https://github.com/ultrafunkamsterdam/undetected-chromedriver/discussions/2282
331
+ # if alt_cls_webdriverwrapper is not None and alt_cls_webdriverwrapper.__module__ in {'undetected_chromedriver'}:
332
+ # browsersettings.add_argument("--disable-dev-shm-usage")
333
+ # browsersettings.add_argument("--disable-blink-features=AutomationControlled")
327
334
  # settings in addition to stealth extension from stackoverflow
328
335
  # https://stackoverflow.com/questions/53039551/selenium-webdriver-modifying-navigator-webdriver-flag-to-prevent-selenium-detec
329
336
  # https://stackoverflow.com/questions/67341346/how-to-bypass-cloudflare-bot-protection-in-selenium
330
337
  if stealthmode:
331
- browsersettings.add_experimental_option("excludeSwitches", ["enable-automation"])
332
- browsersettings.add_experimental_option("useAutomationExtension", False)
338
+ if alt_cls_webdriverwrapper is None or alt_cls_webdriverwrapper.__module__ not in {'undetected_chromedriver'}:
339
+ browsersettings.add_experimental_option("excludeSwitches", ["enable-automation"])
340
+ browsersettings.add_experimental_option("useAutomationExtension", False)
333
341
  browsersettings.add_argument("--disable-blink-features=AutomationControlled")
334
342
  # settings for extensions (partially redundant to BiDi activation)
335
- browsersettings.add_argument("--remote-debugging-pipe")
343
+ # browsersettings.add_argument("--remote-debugging-pipe") # switch was recently deleted,now causes error!
336
344
  browsersettings.add_argument("--enable-unsafe-extension-debugging")
337
345
 
338
346
  # settings for #BiDi
@@ -345,8 +353,8 @@ def init_webdriver(
345
353
  elif browser == "firefox":
346
354
 
347
355
  # set options object - some wrappers define own options class
348
- browsersettings = utils_seleniumxp.WebDriver.FirefoxOptions() if alt_cls_options is None else alt_cls_options()
349
- assert isinstance(browsersettings, utils_seleniumxp._RemoteWebDriver.FireFoxOptions)
356
+ browsersettings = utils_seleniumxp.FirefoxOptions() if alt_cls_options is None else alt_cls_options()
357
+ assert isinstance(browsersettings, utils_seleniumxp.FireFoxOptions)
350
358
 
351
359
  # options / preferences
352
360
  if len(settings) > 0:
@@ -381,13 +389,13 @@ def init_webdriver(
381
389
 
382
390
  # instantiate Selenium webdriver + browser, load blank page
383
391
  if browser == "chrome":
384
- cls_webdriver = utils_seleniumxp.WebDriver.Chrome
392
+ cls_webdriver = utils_seleniumxp.Chrome
385
393
  if alt_cls_webdriverwrapper is not None:
386
394
  if (browser.upper() in [mro_cls.__module__.upper() for mro_cls in alt_cls_webdriverwrapper.__mro__]) or \
387
395
  ("selenium.webdriver.chrome.webdriver" in [mro_cls.__module__ for mro_cls in alt_cls_webdriverwrapper.__mro__]):
388
396
  cls_webdriver = alt_cls_webdriverwrapper # type: ignore[assignment]
389
397
  elif browser == "firefox":
390
- cls_webdriver = utils_seleniumxp.WebDriver.Firefox # type: ignore[assignment]
398
+ cls_webdriver = utils_seleniumxp.Firefox # type: ignore[assignment]
391
399
  if alt_cls_webdriverwrapper is not None:
392
400
  if (browser.upper() in [mro_cls.__module__.upper() for mro_cls in alt_cls_webdriverwrapper.__mro__]) or \
393
401
  ("selenium.webdriver.firefox.webdriver" in [mro_cls.__module__ for mro_cls in alt_cls_webdriverwrapper.__mro__]):
@@ -477,6 +485,17 @@ def init_webdriver(
477
485
  # set logging for closing popups
478
486
  set_log_closepopup(webdriver, config, inisection)
479
487
 
488
+ # activate smartwait
489
+ # NOTE: smartwait with waitless creates a wrapper -> potential inner class must be complete before calling
490
+ if smartwait:
491
+ if smartwait_mode == "autowait":
492
+ from selenium_autowait import enable_autowait
493
+ enable_autowait(timeout=5.0)
494
+ elif smartwait_mode == "waitless":
495
+ from waitless import stabilize
496
+ webdriver = stabilize(webdriver)
497
+ webdriver._smartwait_mode = smartwait_mode
498
+
480
499
  # make sure closepopup log is closed when application ends
481
500
  atexit.register(close_log_closepopup, webdriver)
482
501
  # make sure webdriver process is killed when application ends
@@ -494,11 +513,12 @@ def initWebDriver(
494
513
  maxpageload: int = 30,
495
514
  mixin: bool = utils_seleniumxp.mixinactive,
496
515
  eventlistener: utils_seleniumxp.eventfiring_addon.AbstractEventListenerExtended | None = None,
516
+ smartwait: bool = smartwait_default,
497
517
  stealthmode: bool = stealthmode_default,
498
518
  optimizedscraping: bool = optimizedscraping_default,
499
519
  URL: str = "about:blank",
500
520
  alt_cls_webdriverwrapper: utils_seleniumxp._RemoteWebDriver | None = None,
501
- alt_cls_options: utils_seleniumxp.WebDriver.ChromeOptions | utils_seleniumxp.WebDriver.FirefoxOptions | None = None
521
+ alt_cls_options: utils_seleniumxp.ChromeOptions | utils_seleniumxp.FirefoxOptions | None = None
502
522
  ) -> utils_seleniumxp._RemoteWebDriver:
503
523
  """
504
524
  initWebDriver - initialize Selenium webdriver session
@@ -528,11 +548,12 @@ def initWebDriver(
528
548
  maxpageload (int, optional): max pageload time. Defaults to 20.
529
549
  mixin (bool, optional): flag to switch between mixin and setattr mode. Defaults to utils_seleniumxp.mixinactive.
530
550
  eventlistener (Optional[utils_seleniumxp.eventfiring_addon.AbstractEventListenerExtended], optional): eventlistener object to activate eventfiring mode. Defaults to None.
551
+ smartwait (bool, optional): flag to activate "smart" wait
531
552
  stealthmode (bool, optional): flag to control selenium_stealth mode. Defaults to stealthmode_default.
532
553
  optimizedscraping (bool, optional): flag to control optimized settings for scraping (no pictures etc.). Defaults to optimizedscraping_default.
533
554
  URL (str, optional): start URL. Defaults to "about:blank".
534
555
  alt_cls_webdriverwrapper (Optional[utils_seleniumxp.WebDriver], optional): optional base webdriver class. Defaults to None.
535
- alt_cls_options (Union[utils_seleniumxp.WebDriver.ChromeOptions, utils_seleniumxp.WebDriver.FirefoxOptions, None], optional): optional browser options class. Defaults to None.
556
+ alt_cls_options (Union[utils_seleniumxp.ChromeOptions, utils_seleniumxp.FirefoxOptions, None], optional): optional browser options class. Defaults to None.
536
557
 
537
558
  Returns:
538
559
  utils_seleniumxp.WebDriver: webdriver object
@@ -540,7 +561,7 @@ def initWebDriver(
540
561
  return init_webdriver(
541
562
  browser, inifile, inisection, settings, debugport,
542
563
  implicitlywait, maxpageload, mixin, eventlistener,
543
- stealthmode, optimizedscraping, URL,
564
+ smartwait, stealthmode, optimizedscraping, URL,
544
565
  alt_cls_webdriverwrapper, alt_cls_options
545
566
  )
546
567
 
@@ -588,6 +609,7 @@ def connect_chrome(
588
609
  inisection: str = "DEFAULT",
589
610
  mixin: bool = utils_seleniumxp.mixinactive,
590
611
  eventlistener: utils_seleniumxp.AbstractEventListener | None = None,
612
+ smartwait: bool = smartwait_default,
591
613
  URL: str = "about:blank"
592
614
  ) -> utils_seleniumxp._RemoteWebDriver | None:
593
615
  """
@@ -599,6 +621,7 @@ def connect_chrome(
599
621
  inisection (str, optional): INI section to be evaluated. Defaults to "DEFAULT".
600
622
  mixin (bool, optional): flag to switch between mixin and setattr mode. Defaults to utils_seleniumxp.mixinactive.
601
623
  eventlistener (Optional[utils_seleniumxp.eventfiring_addon.AbstractEventListenerExtended], optional): eventlistener object to activate eventfiring mode. Defaults to None.
624
+ smartwait (bool, optional): flag to activate "smart" wait
602
625
  URL (str, optional): start URL. Defaults to "about:blank".
603
626
 
604
627
  Returns:
@@ -639,17 +662,17 @@ def connect_chrome(
639
662
  os.environ["PATH"] += os.pathsep + driverpath # type: ignore[operator]
640
663
 
641
664
  # create browser options / profile object and set preferences
642
- browsersettings = utils_seleniumxp.WebDriver.ChromeOptions()
665
+ browsersettings = utils_seleniumxp.ChromeOptions()
643
666
  # connect to existing browser instance via debug-port (chrome only)
644
667
  browsersettings.add_experimental_option("debuggerAddress", f"localhost:{debugport}")
645
668
 
646
669
  # instantiate Selenium webdriver, load blank page
647
670
  if mixin or utils_seleniumxp.mixinactive:
648
- webdriver = utils_seleniumxp.webdriver_addon.WebDriverMixedin(utils_seleniumxp.WebDriver.Chrome)(
671
+ webdriver = utils_seleniumxp.webdriver_addon.WebDriverMixedin(utils_seleniumxp.Chrome)(
649
672
  options=browsersettings
650
673
  )
651
674
  else:
652
- webdriver = utils_seleniumxp.webdriver_addon.WebDriverMixedinOnly3rdParty(utils_seleniumxp.WebDriver.Chrome)(
675
+ webdriver = utils_seleniumxp.webdriver_addon.WebDriverMixedinOnly3rdParty(utils_seleniumxp.Chrome)(
653
676
  options=browsersettings
654
677
  )
655
678
  if eventlistener is not None:
@@ -662,6 +685,17 @@ def connect_chrome(
662
685
  # set logging for closepopup
663
686
  set_log_closepopup(webdriver, config, inisection)
664
687
 
688
+ # activate smartwait
689
+ # NOTE: smartwait with waitless creates a wrapper -> potential inner class must be complete before calling
690
+ if smartwait:
691
+ if smartwait_mode == "autowait":
692
+ from selenium_autowait import enable_autowait
693
+ enable_autowait(timeout=5.0)
694
+ elif smartwait_mode == "waitless":
695
+ from waitless import stabilize
696
+ webdriver = stabilize(webdriver)
697
+ webdriver._smartwait_mode = smartwait_mode
698
+
665
699
  # get URL
666
700
  if URL != "about:blank":
667
701
  webdriver.get(URL)
@@ -681,6 +715,7 @@ def connectChrome(
681
715
  inisection: str = "DEFAULT",
682
716
  mixin: bool = utils_seleniumxp.mixinactive,
683
717
  eventlistener: utils_seleniumxp.AbstractEventListener | None = None,
718
+ smartwait: bool = smartwait_default,
684
719
  URL: str = "about:blank"
685
720
  ) -> utils_seleniumxp._RemoteWebDriver | None:
686
721
  """
@@ -692,12 +727,13 @@ def connectChrome(
692
727
  inisection (str, optional): INI section to be evaluated. Defaults to "DEFAULT".
693
728
  mixin (bool, optional): flag to switch between mixin and setattr mode. Defaults to utils_seleniumxp.mixinactive.
694
729
  eventlistener (Optional[utils_seleniumxp.eventfiring_addon.AbstractEventListenerExtended], optional): eventlistener object to activate eventfiring mode. Defaults to None.
730
+ smartwait (bool, optional): flag to activate "smart" wait
695
731
  URL (str, optional): start URL. Defaults to "about:blank".
696
732
 
697
733
  Returns:
698
734
  utils_seleniumxp.WebDriver: webdriver object
699
735
  """
700
- return connect_chrome(debugport, inifile, inisection, mixin, eventlistener, URL)
736
+ return connect_chrome(debugport, inifile, inisection, mixin, eventlistener, smartwait, URL)
701
737
 
702
738
 
703
739
 
@@ -967,20 +1003,25 @@ def getChromeUserDataDir(webdriver: utils_seleniumxp._RemoteWebDriver | None = N
967
1003
  str: user-data-dir ist set in command line
968
1004
  """
969
1005
 
1006
+ # look in capabilities of webdriver object
970
1007
  if webdriver is not None:
971
- return webdriver.caps["chrome"]["userDataDir"]
972
- else:
973
- for p in psutil.process_iter(['name', 'cmdline']):
974
- if p.info['name'] and 'chrome' in p.info['name'].lower():
975
- cmd = p.info['cmdline']
976
- for arg in cmd:
977
- if arg.startswith("--user-data-dir="):
978
- return arg.split("=", 1)[1]
1008
+ try:
1009
+ return webdriver.caps["chrome"]["userDataDir"]
1010
+ except Exception:
1011
+ pass
1012
+
1013
+ # look in command lines of running Chrome processes
1014
+ for p in psutil.process_iter(['name', 'cmdline']):
1015
+ if p.info['name'] and 'chrome' in p.info['name'].lower():
1016
+ cmd = p.info['cmdline']
1017
+ for arg in cmd:
1018
+ if arg.startswith("--user-data-dir="):
1019
+ return arg.split("=", 1)[1]
979
1020
  return None
980
1021
 
981
- def get_Chrome_userdata_dir(webdriver: utils_seleniumxp._RemoteWebDriver | None) -> str | None:
1022
+ def get_chrome_userdata_dir(webdriver: utils_seleniumxp._RemoteWebDriver | None) -> str | None:
982
1023
  """
983
- get_Chrome_userdata_dir - get user-data directory set in commandline
1024
+ get_chrome_userdata_dir - get user-data directory set in commandline
984
1025
 
985
1026
  Args:
986
1027
  webdriver (utils_seleniumxp._RemoteWebDriver): webdriver object
@@ -1005,16 +1046,19 @@ def kill_driver_processes(browser: str = "chrome", pid: int | None = None) -> No
1005
1046
  err_msg = f"Browser '{browser}' not supported."
1006
1047
  raise utils_seleniumxp.ErrorUtilsSelenium(err_msg)
1007
1048
 
1049
+ # 1st try via pid stored
1050
+ with contextlib.suppress(psutil.NoSuchProcess, psutil.AccessDenied, KeyboardInterrupt):
1051
+ # psutil.Process(pid).send_signal(signal.SIGTERM)
1052
+ psutil.Process(pid).terminate()
1053
+ # 2nd try via finding pids running driverbinary
1008
1054
  driverbinary: str = supported_browsers[browser][1]
1009
- with contextlib.suppress(psutil.NoSuchProcess):
1010
- psutil.Process(pid).send_signal(signal.SIGTERM)
1011
1055
  pids: list[int] = []
1012
- try:
1013
- for proc in psutil.process_iter(["name"]):
1014
- if proc.info["name"] == driverbinary:
1015
- if pid is None or pid == proc.pid:
1016
- pids.append(proc.pid)
1017
- except Exception:
1018
- pass
1056
+ with contextlib.suppress(Exception, KeyboardInterrupt):
1057
+ for proc in psutil.process_iter(["pid", "name"]):
1058
+ with contextlib.suppress(psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess, OSError):
1059
+ if proc.info["name"] == driverbinary:
1060
+ if pid is None or pid == proc.pid:
1061
+ pids.append(proc.pid)
1019
1062
  for pid in pids: # noqa: PLR1704
1020
- psutil.Process(pid).send_signal(signal.SIGTERM)
1063
+ # psutil.Process(pid).send_signal(signal.SIGTERM)
1064
+ psutil.Process(pid).terminate()
@@ -6,7 +6,7 @@ Based on <https://github.com/maresb/hatch-vcs-footgun-example>.
6
6
 
7
7
  # ruff and mypy per file settings
8
8
  # others
9
- # ruff: noqa: PLC0415
9
+ # ruff: noqa: E302, PLC0415, RUF105
10
10
 
11
11
  # fmt: off
12
12
 
@@ -14,11 +14,11 @@ Based on <https://github.com/maresb/hatch-vcs-footgun-example>.
14
14
  def _get_hatch_version():
15
15
  """Compute the most up-to-date version number in a development environment.
16
16
 
17
- Returns `None` if Hatchling is not installed, e.g. in a production environment.
18
-
19
17
  For more details, see <https://github.com/maresb/hatch-vcs-footgun-example/>.
20
18
  """
21
19
  import os
20
+ # preparation for Pathlib
21
+ # from pathlib import path
22
22
 
23
23
  try:
24
24
  from hatchling.metadata.core import ProjectMetadata
@@ -33,9 +33,19 @@ def _get_hatch_version():
33
33
  err_msg = "pyproject.toml not found although hatchling is installed"
34
34
  raise RuntimeError(err_msg)
35
35
  root = os.path.dirname(pyproject_toml)
36
- metadata = ProjectMetadata(root=root, plugin_manager=PluginManager())
37
- # Version can be either statically set in pyproject.toml or computed dynamically:
38
- return metadata.core.version or metadata.hatch.version.cached
36
+ # preparation for Pathlib
37
+ # root = Path(pyproject_toml).parent
38
+ # Temporarily set cwd to project root for PEP 517 compliance.
39
+ old_cwd = os.getcwd()
40
+ # preparation for Pathlib
41
+ # old_cwd = Path.cwd()
42
+ os.chdir(root)
43
+ try:
44
+ metadata = ProjectMetadata(root=str(root), plugin_manager=PluginManager())
45
+ # Version can be static in pyproject.toml or computed dynamically:
46
+ return metadata.core.version or metadata.hatch.version.cached
47
+ finally:
48
+ os.chdir(old_cwd)
39
49
 
40
50
 
41
51
  def _get_importlib_metadata_version():
@@ -1,5 +1,6 @@
1
1
  # Selenium webdriver utilities - XP version
2
2
  # webdriver class - additional functionalities
3
+ # implementaiton via mixin class or monkey-patching alternatively
3
4
 
4
5
  """
5
6
  module with webdriver class extensions
@@ -21,7 +22,7 @@ Webdriver extensions include:
21
22
  # boolean-type arguments
22
23
  # ruff: noqa: FBT001, FBT002
23
24
  # others
24
- # ruff: noqa: B010, E301, E305, E501, PLR0904, PLR0914, PLR0917, PLR1702, PLR5501, S101, SIM102
25
+ # ruff: noqa: B010, E301, E305, E501, PLR0904, PLR0914, PLR0917, PLR1702, PLR5501, PLW0717, RUF075, RUF105, S101, SIM102
25
26
  #
26
27
  # disable mypy errors
27
28
  # mypy: disable-error-code = "no-any-return, attr-defined, unused-ignore"
@@ -31,17 +32,16 @@ Webdriver extensions include:
31
32
 
32
33
 
33
34
  # TODO Dev:
34
- # - more comfortable wait_for
35
- # params element, condition, timeout
35
+ # - smartwait module -> implement in webdriver_addon
36
+ # - restructure module for better maintainability (clearer structure, shorter module(s)
37
+ # - Mixin-class related stuff remains in webdriver_addon.py
38
+ # - webdriver subdirectory and submoduls for wait support, closepopup, element helpers / shadowDOM
39
+ # - from <module> import *
40
+ # - pilot with wait_helper
36
41
  # - find_element_frames -> loop across frames automatically?
37
42
  # - integrate new Selenium 4.x API functions
38
43
  # - scroll from Actions-API (instead of script calling)
39
44
  # see https://www.selenium.dev/documentation/webdriver/actions_api/wheel/
40
- # - automatic retry for find_element(s) (see seleniumbase as inspiration) ?
41
- # approach 1: derived class with redefinition and call of super-method
42
- # approach 2: create wrapped method and re-direct call via setattr
43
- # - implement additional helpers like automated findwait_for_element, download (see horejsek wrapper or selgym)
44
- # alternatively: derived class with redefinition and call of super method?
45
45
 
46
46
  # TODO Test:
47
47
  # - n. a.
@@ -73,7 +73,7 @@ import utils_seleniumxp
73
73
 
74
74
  # webdriver mixins approach - require Mixin classes to be used for additional functionality
75
75
  # mixin-class required per browser specific webdriver class
76
- # optional: use setattr (assumption: derived wrapper classes should automatically inherit methods)
76
+ # optional: monkey-patching by setattr (assumption: derived wrapper classes should automatically inherit methods)
77
77
 
78
78
  # mixin object for normal webdriver
79
79
  class _WebDriverMixin:
@@ -502,7 +502,7 @@ def find_root_shadowdom(
502
502
  webdriver (utils_seleniumxp._RemoteWebDriver): browser
503
503
  locator_list: (Union[utils_seleniumxp.SeleniumLocator, list[utils_seleniumxp.SeleniumLocator]], optional): locator list to shadowDOM host. Defaults to None.
504
504
  loggercall: (Callable, optional) = log function for error. Defaults to None.
505
- raise_exception: (bool): flag to raise exception inc ase of any error in shadowDOM evaluation. Defaults to False.
505
+ raise_exception: (bool): flag to raise exception in case of any error in shadowDOM evaluation. Defaults to False.
506
506
  debug (bool): flag for debug mode to process every nesting level in shadowDOM separately. Defaults to False.
507
507
 
508
508
  Returns:
@@ -638,7 +638,6 @@ def find_elements_shadowdom(
638
638
  if shadowroot is None:
639
639
  err_msg = "Provided webelement is neither a ShadowRoot nor a ShadowHost."
640
640
  raise utils_seleniumxp.ErrorUtilsSelenium(err_msg)
641
- return None
642
641
  # overcome issue with id attribute, discovered missing in JSON return when accessing shadow root in May 2025
643
642
  if not hasattr(shadowroot, "id"):
644
643
  shadowroot.id = shadowroot._id # type: ignore[misc]
@@ -769,7 +768,7 @@ def hover_over_element(
769
768
  else:
770
769
  shadowroot = webdriver.find_root_shadowdom_simple(by_host, value_host)
771
770
  webelement = webdriver.find_element_shadowdom_simple(by, value, shadowroot)
772
- utils_seleniumxp.WebDriver.ActionChains(webdriver).move_to_element(webelement).perform()
771
+ utils_seleniumxp.ActionChains(webdriver).move_to_element(webelement).perform()
773
772
 
774
773
  # direct settattr instead of mixin-object but avoid name conflict
775
774
  # (not relevant for EventFiringWebDriver)
@@ -988,11 +987,12 @@ def closepopup_queueprocessing(webdriver: utils_seleniumxp._RemoteWebDriver, fir
988
987
  # if hasattr(webdriver, "closepopup_logger"):
989
988
  # webdriver.closepopup_logger.info(f"ShadowDOM host not unique\t{webdriver.current_url}\t({locator_click})\t({locator_iframe})\t({locator_shadowdomhost})")
990
989
  # continue
991
- shadowroot = webdriver.find_root_shadowdom(locator_shadowdomhost, webdriver.closepopup_logger.info, raise_exception=False)
990
+ shadowroot = webdriver.find_root_shadowdom(locator_shadowdomhost, webdriver.closepopup_logger.info if hasattr(webdriver, "closepopup_logger") else None, raise_exception=False)
992
991
  if shadowroot is not None:
993
992
  webelts = shadowroot.find_elements(*locator_click)
994
993
  else:
995
- webdriver.closepopup_logger.info(f"ShadowDOM root not found \t{webdriver.current_url}\t({locator_click})\t({locator_iframe})\t({locator_shadowdomhost})")
994
+ if hasattr(webdriver, "closepopup_logger"):
995
+ webdriver.closepopup_logger.info(f"ShadowDOM root not found \t{webdriver.current_url}\t({locator_click})\t({locator_iframe})\t({locator_shadowdomhost})")
996
996
  else:
997
997
  if utils_seleniumxp.locatorutils.check_locator(locator_click, {utils_seleniumxp.By.XPATH, utils_seleniumxp.By.CSS_SELECTOR}):
998
998
  webelts = parsedhtml.css_or_xpath(locator_click).getall()
@@ -1323,28 +1323,31 @@ def wait4AJAX(webdriver: utils_seleniumxp._RemoteWebDriver, timeout: int = 10, m
1323
1323
  bool: flag if timeout reached
1324
1324
  """
1325
1325
 
1326
- starttime = time.time()
1327
- timeoutscript = False
1328
- try:
1329
- utils_seleniumxp.WebDriverWait(webdriver, 1).until(lambda webdriver: webdriver.execute_script('return jQuery.active') == 0)
1330
- except (utils_seleniumxp.WebDriverExceptions.JavascriptException, utils_seleniumxp.WebDriverExceptions.TimeoutException):
1331
- pass
1332
- else:
1326
+ # check "smartwait" mode not used
1327
+ if not getattr(webdriver, "_smartwait", None):
1328
+ # chek jQuery state
1329
+ starttime = time.time()
1330
+ timeoutscript = False
1331
+ try:
1332
+ utils_seleniumxp.WebDriverWait(webdriver, 1).until(lambda webdriver: webdriver.execute_script('return jQuery.active') == 0)
1333
+ except (utils_seleniumxp.WebDriverExceptions.JavascriptException, utils_seleniumxp.WebDriverExceptions.TimeoutException):
1334
+ pass
1335
+ else:
1336
+ try:
1337
+ utils_seleniumxp.WebDriverWait(webdriver, timeout).until(lambda webdriver: webdriver.execute_script('return jQuery.active') == 0)
1338
+ except utils_seleniumxp.WebDriverExceptions.TimeoutException:
1339
+ timeoutscript = True
1340
+ # check document.readyState
1341
+ timeoutdocrs = False
1333
1342
  try:
1334
- utils_seleniumxp.WebDriverWait(webdriver, timeout).until(lambda webdriver: webdriver.execute_script('return jQuery.active') == 0)
1343
+ utils_seleniumxp.WebDriverWait(webdriver, timeout).until(lambda webdriver: webdriver.execute_script('return document.readyState') == 'complete')
1335
1344
  except utils_seleniumxp.WebDriverExceptions.TimeoutException:
1336
- timeoutscript = True
1337
-
1338
- timeoutdocrs = False
1339
- try:
1340
- utils_seleniumxp.WebDriverWait(webdriver, timeout).until(lambda webdriver: webdriver.execute_script('return document.readyState') == 'complete')
1341
- except utils_seleniumxp.WebDriverExceptions.TimeoutException:
1342
- timeoutdocrs = True
1343
-
1344
- while (time.time() < starttime + min_wait):
1345
- time.sleep(0.1)
1346
-
1347
- return timeoutscript or timeoutdocrs
1345
+ timeoutdocrs = True
1346
+ while (time.time() < starttime + min_wait):
1347
+ time.sleep(0.1)
1348
+ return timeoutscript or timeoutdocrs
1349
+ else:
1350
+ return False
1348
1351
 
1349
1352
  # wait for HTML, AJAX script and readyState
1350
1353
  def wait4HTMLstable(webdriver: utils_seleniumxp._RemoteWebDriver, wait: float = 0.1, max_wait: float = 0.5) -> bool:
@@ -1360,14 +1363,20 @@ def wait4HTMLstable(webdriver: utils_seleniumxp._RemoteWebDriver, wait: float =
1360
1363
  bool: flag if page source is stable
1361
1364
  """
1362
1365
 
1363
- wait4AJAX(webdriver)
1364
- HTMLprev = ""
1365
- starttime = time.time()
1366
- while (HTMLprev != webdriver.page_source and (time.time() < starttime + max_wait)):
1367
- HTMLprev = webdriver.page_source
1368
- time.sleep(wait)
1366
+ # check "smartwait" mode not used
1367
+ if not getattr(webdriver, "_smartwait", None):
1368
+ # call "lower" level wait
1369
+ wait4AJAX(webdriver)
1370
+ HTMLprev = ""
1371
+ starttime = time.time()
1372
+ # check for HTML source stable
1373
+ while (HTMLprev != webdriver.page_source and (time.time() < starttime + max_wait)):
1374
+ HTMLprev = webdriver.page_source
1375
+ time.sleep(wait)
1376
+ return HTMLprev == webdriver.page_source
1377
+ else:
1378
+ return True
1369
1379
 
1370
- return HTMLprev == webdriver.page_source
1371
1380
 
1372
1381
  # direct setattr instead of mixin-object but avoid name conflict
1373
1382
  if not utils_seleniumxp.mixinactive:
@@ -1,6 +1,7 @@
1
1
  # Selenium webdriver utilities - XP version
2
2
  # webelement - additional functionalities
3
3
  # wrapper class not possible as WebElement class is referred to by general webdriver class
4
+ # so monkey-patching approach only
4
5
 
5
6
  """
6
7
  module with webelement class extensions
@@ -21,7 +22,7 @@ Webelement extensions include:
21
22
  # boolean-type arguments
22
23
  # ruff: noqa: FBT001, FBT002
23
24
  # others
24
- # ruff: noqa: B010, E305, E501
25
+ # ruff: noqa: B010, E305, E501, RUF105
25
26
  #
26
27
  # disable mypy errors
27
28
  # mypy: disable-error-code = "no-any-return, attr-defined"
@@ -32,8 +33,7 @@ Webelement extensions include:
32
33
 
33
34
 
34
35
  # TODO Dev:
35
- # - extension for mixin classes / own routines
36
- # - click_and_wait (possibly include scroll_into_view) ?
36
+ # - n. a.
37
37
 
38
38
  # TODO Test:
39
39
  # - n. a.
@@ -96,7 +96,7 @@ def hover_over(webelement: utils_seleniumxp._WebElement) -> None:
96
96
  webelement (utils_seleniumxp._WebElement): webelement
97
97
  """
98
98
 
99
- utils_seleniumxp.WebDriver.ActionChains(webelement.parent).move_to_element(webelement).perform()
99
+ utils_seleniumxp.ActionChains(webelement.parent).move_to_element(webelement).perform()
100
100
 
101
101
  # no mixin-object for WebElement -> direct settattr
102
102
  setattr(utils_seleniumxp._WebElement, "hover_over", hover_over)