QWeb 3.3.3__tar.gz → 3.4.1__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.
Files changed (84) hide show
  1. {QWeb-3.3.3 → qweb-3.4.1}/PKG-INFO +23 -3
  2. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/__main__.py +2 -2
  3. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/_version.py +3 -3
  4. qweb-3.4.1/QWeb/internal/browser/chrome.py +163 -0
  5. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/browser/edge.py +8 -2
  6. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/browser/firefox.py +11 -2
  7. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/browser/safari.py +9 -4
  8. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/frame.py +65 -20
  9. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/icon.py +44 -50
  10. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/text.py +54 -13
  11. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/browser.py +7 -0
  12. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/config.py +32 -0
  13. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/element.py +10 -1
  14. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/frame.py +3 -0
  15. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/table.py +9 -0
  16. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/text.py +15 -5
  17. {QWeb-3.3.3 → qweb-3.4.1}/QWeb.egg-info/PKG-INFO +23 -3
  18. {QWeb-3.3.3 → qweb-3.4.1}/QWeb.egg-info/requires.txt +11 -6
  19. {QWeb-3.3.3 → qweb-3.4.1}/setup.py +10 -8
  20. {QWeb-3.3.3 → qweb-3.4.1}/versioneer.py +10 -3
  21. QWeb-3.3.3/QWeb/internal/browser/chrome.py +0 -137
  22. {QWeb-3.3.3 → qweb-3.4.1}/LICENSE +0 -0
  23. {QWeb-3.3.3 → qweb-3.4.1}/MANIFEST.in +0 -0
  24. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/__init__.py +0 -0
  25. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/custom_config.py +0 -0
  26. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/__init__.py +0 -0
  27. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/actions.py +0 -0
  28. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/ajax.py +0 -0
  29. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/alert.py +0 -0
  30. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/blocks.py +0 -0
  31. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/browser/__init__.py +0 -0
  32. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/browser/android.py +0 -0
  33. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/browser/bs_desktop.py +0 -0
  34. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/browser/bs_mobile.py +0 -0
  35. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/checkbox.py +0 -0
  36. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/config.py +0 -0
  37. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/config_defaults.py +0 -0
  38. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/cookies.py +0 -0
  39. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/decorators.py +0 -0
  40. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/download.py +0 -0
  41. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/dragdrop.py +0 -0
  42. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/dropdown.py +0 -0
  43. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/element.py +0 -0
  44. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/exceptions.py +0 -0
  45. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/file.py +0 -0
  46. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/frame_checker.py +0 -0
  47. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/input_.py +0 -0
  48. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/input_handler.py +0 -0
  49. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/javascript.py +0 -0
  50. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/lists.py +0 -0
  51. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/meas.py +0 -0
  52. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/platform.py +0 -0
  53. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/screenshot.py +0 -0
  54. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/search_strategy.py +0 -0
  55. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/secrets.py +0 -0
  56. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/table.py +0 -0
  57. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/user.py +0 -0
  58. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/util.py +0 -0
  59. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/window.py +0 -0
  60. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/internal/xhr.py +0 -0
  61. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/__init__.py +0 -0
  62. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/ajax.py +0 -0
  63. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/alert.py +0 -0
  64. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/blocks.py +0 -0
  65. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/checkbox.py +0 -0
  66. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/cookies.py +0 -0
  67. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/debug.py +0 -0
  68. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/download.py +0 -0
  69. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/dragdrop.py +0 -0
  70. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/dropdown.py +0 -0
  71. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/file.py +0 -0
  72. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/icon.py +0 -0
  73. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/input_.py +0 -0
  74. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/javascript.py +0 -0
  75. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/lists.py +0 -0
  76. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/screenshot.py +0 -0
  77. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/search_strategy.py +0 -0
  78. {QWeb-3.3.3 → qweb-3.4.1}/QWeb/keywords/window.py +0 -0
  79. {QWeb-3.3.3 → qweb-3.4.1}/QWeb.egg-info/SOURCES.txt +0 -0
  80. {QWeb-3.3.3 → qweb-3.4.1}/QWeb.egg-info/dependency_links.txt +0 -0
  81. {QWeb-3.3.3 → qweb-3.4.1}/QWeb.egg-info/not-zip-safe +0 -0
  82. {QWeb-3.3.3 → qweb-3.4.1}/QWeb.egg-info/top_level.txt +0 -0
  83. {QWeb-3.3.3 → qweb-3.4.1}/README.md +0 -0
  84. {QWeb-3.3.3 → qweb-3.4.1}/setup.cfg +0 -0
@@ -1,22 +1,42 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: QWeb
3
- Version: 3.3.3
3
+ Version: 3.4.1
4
4
  Summary: Keyword driven automation for the web
5
5
  Home-page: https://github.com/qentinelqi/qweb/
6
- Author: Qentinel Group
7
- Author-email: libraries@qentinel.com
6
+ Author: Copado Inc.
7
+ Author-email: copadorobotictesting@copado.com
8
8
  License: Apache License 2.0
9
9
  Keywords: test automation robot framework
10
10
  Classifier: Programming Language :: Python :: 3.8
11
11
  Classifier: Programming Language :: Python :: 3.9
12
12
  Classifier: Programming Language :: Python :: 3.10
13
13
  Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
14
15
  Classifier: License :: OSI Approved :: Apache Software License
15
16
  Classifier: Framework :: Robot Framework
16
17
  Classifier: Framework :: Robot Framework :: Library
17
18
  Requires-Python: >3.7,<4.0
18
19
  Description-Content-Type: text/markdown
19
20
  License-File: LICENSE
21
+ Requires-Dist: setuptools>=70.0.0
22
+ Requires-Dist: pyscreeze==0.1.28
23
+ Requires-Dist: pyautogui>=0.9.53
24
+ Requires-Dist: pynput>=1.7.7
25
+ Requires-Dist: requests>=2.32.2
26
+ Requires-Dist: robotframework<8,>=4.1.3
27
+ Requires-Dist: robotframework-debuglibrary==2.5.0
28
+ Requires-Dist: selenium<5,>=4.16.0
29
+ Requires-Dist: Pillow<11,>=10.3.0
30
+ Requires-Dist: scipy>=1.7.3
31
+ Requires-Dist: scikit-image==0.21; python_version == "3.8"
32
+ Requires-Dist: scikit-image==0.24; python_version > "3.8"
33
+ Requires-Dist: ply
34
+ Requires-Dist: numpy<2,>=1.23.5
35
+ Requires-Dist: opencv-python==4.8.1.78
36
+ Requires-Dist: slate3k>=0.5.3
37
+ Requires-Dist: xlib; "linux" in sys_platform
38
+ Requires-Dist: pyobjc-core>=9.2; "darwin" in sys_platform
39
+ Requires-Dist: pyobjc>=9.2; "darwin" in sys_platform
20
40
 
21
41
  <img id="qweb" src="https://github.com/qentinelqi/qweb/raw/master/images/qweb.png" alt="QWeb">
22
42
 
@@ -26,9 +26,9 @@ def cli() -> None:
26
26
  usage="python %(prog)s [options] INPUT"
27
27
  "\n\nEXAMPLES:\n"
28
28
  "%(prog)s --all (lists all keywords)\n"
29
- '%(prog)s --list Get (lists all keywords startin with "Get")\n'
29
+ '%(prog)s --list Get (lists all keywords starting with "Get")\n'
30
30
  '%(prog)s --show TypeText (displays documentation for keyword "TypeText")',
31
- description="Note: This module is meant to be used as a robot famework library."
31
+ description="Note: This module is meant to be used as a robot framework library."
32
32
  "Command line interface only provides access to keyword documentation.",
33
33
  )
34
34
  parser.add_argument(
@@ -8,11 +8,11 @@ import json
8
8
 
9
9
  version_json = '''
10
10
  {
11
- "date": "2024-06-28T09:04:34+0300",
11
+ "date": "2024-09-14T12:17:47+0300",
12
12
  "dirty": false,
13
13
  "error": null,
14
- "full-revisionid": "1fd8313d64c90c88d8b0b69df22b0430a358ca74",
15
- "version": "v3.3.3"
14
+ "full-revisionid": "bf8ef0d847061c0b084705487e81805e23631af2",
15
+ "version": "v3.4.1"
16
16
  }
17
17
  ''' # END VERSION_JSON
18
18
 
@@ -0,0 +1,163 @@
1
+ from __future__ import annotations
2
+ import os
3
+ from typing import Optional, Any
4
+ from selenium.webdriver.remote.webdriver import WebDriver
5
+ from selenium.webdriver import Chrome
6
+ from selenium.webdriver.chrome.options import Options
7
+ from selenium.webdriver.chrome.service import Service
8
+ from robot.api import logger
9
+ from robot.libraries.BuiltIn import BuiltIn, RobotNotRunningError
10
+ from QWeb.internal import browser, user, util
11
+ from QWeb.internal.config_defaults import CONFIG
12
+
13
+ NAMES: list[str] = ["chrome", "gc"]
14
+
15
+
16
+ def check_browser_reuse(**kwargs: Any) -> tuple[bool, Optional[str], Optional[str]]:
17
+ try:
18
+ browser_reuse = util.par2bool(util.get_rfw_variable_value("${BROWSER_REUSE}")) or False
19
+ dbg_addr = kwargs.get("debugger_address", None) or util.get_rfw_variable_value(
20
+ "${BROWSER_DEBUGGER_ADDRESS}"
21
+ )
22
+ executor_url = kwargs.get("executor_url", None) or util.get_rfw_variable_value(
23
+ "${BROWSER_EXECUTOR_URL}"
24
+ )
25
+ return browser_reuse, dbg_addr, executor_url
26
+ except RobotNotRunningError:
27
+ pass
28
+
29
+ return False, None, None
30
+
31
+
32
+ def write_browser_session_argsfile(
33
+ dbg_addr: str, executor_url: str, fname: str = "browser_session.arg"
34
+ ) -> str:
35
+ robot_output = util.get_rfw_variable_value("${OUTPUT DIR}")
36
+ args_fn = os.path.join(robot_output or os.getcwd(), fname)
37
+ with open(args_fn, "w") as args_file:
38
+ args_file.write(f"-v BROWSER_REUSE:{True}{os.linesep}")
39
+ args_file.write(f"-v BROWSER_DEBUGGER_ADDRESS:{dbg_addr}{os.linesep}")
40
+ args_file.write(f"-v BROWSER_EXECUTOR_URL:{executor_url}{os.linesep}")
41
+
42
+ return args_fn
43
+
44
+
45
+ def open_browser(
46
+ executable_path: str = "", chrome_args: Optional[list[str]] = None, **kwargs: Any
47
+ ) -> WebDriver:
48
+ """Open Chrome browser instance and cache the driver.
49
+
50
+ Parameters
51
+ ----------
52
+ executable_path : str (Default "chromedriver")
53
+ path to the executable. If the default is used it assumes the
54
+ executable is in the $PATH.
55
+ port : int (Default 0)
56
+ port you would like the service to run, if left as 0, a free port will
57
+ be found.
58
+ desired_capabilities : dict (Default None)
59
+ Dictionary object with non-browser specific capabilities only, such as
60
+ "proxy" or "loggingPref".
61
+ chrome_args : Optional arguments to modify browser settings
62
+ """
63
+ options = create_chrome_options(chrome_args, **kwargs)
64
+ chromedriver_path = resolve_chromedriver_path(executable_path)
65
+
66
+ browser_reuse, debugger_address, executor_url = check_browser_reuse(**kwargs)
67
+ logger.debug(
68
+ f"browser_reuse: {browser_reuse}, "
69
+ f"executor_url: {executor_url}, "
70
+ f"debugger_address: {debugger_address}"
71
+ )
72
+
73
+ if browser_reuse and executor_url and debugger_address:
74
+ return create_reused_browser(debugger_address)
75
+
76
+ driver = create_new_browser(chromedriver_path, options, **kwargs)
77
+ cache_browser_session(driver)
78
+
79
+ browser.cache_browser(driver)
80
+ return driver
81
+
82
+
83
+ def create_chrome_options(chrome_args: Optional[list[str]], **kwargs: Any) -> Options:
84
+ """Create Chrome options based on arguments and keyword arguments."""
85
+ options = Options()
86
+ options.add_experimental_option("excludeSwitches", ["enable-logging"])
87
+
88
+ if chrome_args:
89
+ if any("headless" in arg.lower() for arg in chrome_args):
90
+ CONFIG.set_value("Headless", True)
91
+ for arg in chrome_args:
92
+ options.add_argument(arg.lstrip())
93
+
94
+ options.add_argument("start-maximized")
95
+ options.add_argument("--disable-notifications")
96
+ options.add_argument("--disable-search-engine-choice-screen")
97
+
98
+ if "headless" in kwargs:
99
+ CONFIG.set_value("Headless", True)
100
+ options.add_argument("headless")
101
+
102
+ if "prefs" in kwargs:
103
+ prefs = util.parse_prefs(kwargs.get("prefs"))
104
+ options.add_experimental_option("prefs", prefs)
105
+
106
+ if "emulation" in kwargs:
107
+ emulate_device = util.get_emulation_pref(kwargs["emulation"])
108
+ options.add_experimental_option("mobileEmulation", emulate_device)
109
+
110
+ chrome_path = kwargs.get("chrome_path", None) or util.get_rfw_variable_value("${CHROME_PATH}")
111
+ if chrome_path:
112
+ options.binary_location = chrome_path
113
+
114
+ chrome_version = (
115
+ kwargs.get("browser_version", None)
116
+ or util.get_rfw_variable_value("${BROWSER_VERSION}")
117
+ )
118
+ if chrome_version:
119
+ options.browser_version = chrome_version
120
+
121
+ if user.is_root():
122
+ options.add_argument("no-sandbox")
123
+
124
+ return options
125
+
126
+
127
+ def resolve_chromedriver_path(executable_path: str) -> str:
128
+ """Resolve the path to the ChromeDriver executable."""
129
+ driver_path = util.get_rfw_variable_value("${CHROMEDRIVER_PATH}") or executable_path
130
+ if driver_path:
131
+ logger.debug(f"Chromedriver path: {driver_path}")
132
+ return driver_path
133
+
134
+
135
+ def create_reused_browser(debugger_address: str) -> WebDriver:
136
+ """Create a browser instance reusing an existing session."""
137
+ options = Options()
138
+ options.add_argument("headless")
139
+ options.debugger_address = debugger_address
140
+ service = Service()
141
+ return Chrome(service=service, options=options)
142
+
143
+
144
+ def create_new_browser(chromedriver_path: str, options: Options, **kwargs: Any) -> WebDriver:
145
+ """Create a new browser instance."""
146
+ remote_url = kwargs.get("remote_url", None)
147
+ if remote_url:
148
+ return WebDriver(command_executor=remote_url, options=options)
149
+
150
+ service = Service(chromedriver_path) if chromedriver_path else Service()
151
+ return Chrome(service=service, options=options)
152
+
153
+
154
+ def cache_browser_session(driver: WebDriver) -> None:
155
+ """Cache the WebDriver session info for reuse."""
156
+ browser_reuse_enabled = (
157
+ util.par2bool(util.get_rfw_variable_value("${BROWSER_REUSE_ENABLED}")) or False
158
+ )
159
+ if browser_reuse_enabled:
160
+ dbg_address = driver.capabilities["goog:chromeOptions"]["debuggerAddress"]
161
+ write_browser_session_argsfile(dbg_address, driver.command_executor._url) # type: ignore # pylint: disable=protected-access
162
+ BuiltIn().set_global_variable("${BROWSER_EXECUTOR_URL}", None)
163
+ BuiltIn().set_global_variable("${BROWSER_DEBUGGER_ADDRESS}", None)
@@ -51,6 +51,8 @@ def open_browser(
51
51
  # parameters instead of opening new chrome session.
52
52
  # New Remote Web Driver is created in headless mode.
53
53
  edgedriver_path = util.get_rfw_variable_value("${EDGEDRIVER_PATH}") or executable_path
54
+ if edgedriver_path:
55
+ logger.debug(f"Edgedriver path: {edgedriver_path}")
54
56
  edge_path = kwargs.get("edge_path", None) or util.get_rfw_variable_value("${EDGE_PATH}")
55
57
  if edge_path:
56
58
  options.binary_location = edge_path # pylint: disable=no-member
@@ -84,8 +86,12 @@ def open_browser(
84
86
  emulate_device = util.get_emulation_pref(emulation)
85
87
  options.add_experimental_option("mobileEmulation", emulate_device)
86
88
 
87
- service = Service(edgedriver_path) if edgedriver_path else Service()
88
- driver = Edge(service=service, options=options)
89
+ remote_url = kwargs.get("remote_url", None)
90
+ if remote_url:
91
+ driver = WebDriver(command_executor=remote_url, options=options)
92
+ else:
93
+ service = Service(edgedriver_path) if edgedriver_path else Service()
94
+ driver = Edge(service=service, options=options)
89
95
 
90
96
  # driver = Edge(
91
97
  # util.get_rfw_variable_value('${EDGEDRIVER_PATH}') # pylint: disable=unexpected-keyword-arg
@@ -104,8 +104,17 @@ def open_browser(
104
104
 
105
105
  if binary:
106
106
  options.binary_location = binary
107
- service = Service(driver_path, log_path=log_path) if driver_path else Service(log_path=log_path)
108
- driver = webdriver.Firefox(service=service, options=options)
107
+
108
+ remote_url = kwargs.get("remote_url", None)
109
+ if remote_url:
110
+ driver = WebDriver(command_executor=remote_url, options=options)
111
+ else:
112
+ service = (
113
+ Service(driver_path, log_path=log_path)
114
+ if driver_path
115
+ else Service(log_path=log_path)
116
+ )
117
+ driver = webdriver.Firefox(service=service, options=options)
109
118
  if os.name == "nt": # Maximize window if running on windows, doesn't work on linux
110
119
  driver.maximize_window()
111
120
  browser.cache_browser(driver)
@@ -17,6 +17,7 @@ def open_browser(
17
17
  driver_path: str = "",
18
18
  desired_capabilities: Optional[dict[str, Any]] = None,
19
19
  quiet: bool = False,
20
+ **kwargs: Any,
20
21
  ) -> WebDriver:
21
22
  options = Options()
22
23
 
@@ -36,12 +37,16 @@ def open_browser(
36
37
  "OpenBrowser\thttps://www.google.com\tsafari\tdesired_capabilities=${caps}"
37
38
  )
38
39
 
39
- if driver_path:
40
- service = service = Service(driver_path, port=port, quiet=quiet)
40
+ remote_url = kwargs.get("remote_url", None)
41
+ if remote_url:
42
+ driver = WebDriver(command_executor=remote_url, options=options)
41
43
  else:
42
- service = Service(port=port, quiet=quiet)
44
+ if driver_path:
45
+ service = Service(driver_path, port=port, quiet=quiet)
46
+ else:
47
+ service = Service(port=port, quiet=quiet)
43
48
 
44
- driver = webdriver.Safari(service=service, options=options)
49
+ driver = webdriver.Safari(service=service, options=options)
45
50
 
46
51
  # If implicit_wait is not > 0 Safaridriver starts raising TimeoutExceptions
47
52
  # instead of proper exception types
@@ -175,38 +175,54 @@ def set_html_source_count(value: Union[int, str]):
175
175
  def all_frames(fn: Callable[..., Any]) -> Callable[..., Any]:
176
176
  """Decorator that takes any func as a parameter.
177
177
 
178
- search_from_frames is recursive function which goes through
179
- all found frames until we find our element if that's not in
180
- main html's dom tree.
178
+ search_from_frames is a recursive function that goes through
179
+ all found frames until we find our element if it's not in
180
+ the main HTML's DOM tree.
181
181
  """
182
182
 
183
183
  @wraps(fn)
184
184
  def wrapped(*args, **kwargs) -> Callable[..., Any]:
185
+ # Default behavior is not to continue searching
186
+ continue_search = kwargs.get("continue_search", False)
187
+
188
+ # pylint: disable=too-many-branches
185
189
  def search_from_frames(
186
190
  driver: Optional[WebDriver] = None, current_frame: Optional[WebElement] = None
187
191
  ) -> Callable[..., Any]:
192
+ # Initialize the list to store found elements if continue_search is True
193
+ all_elements = []
188
194
  keep_frame = kwargs.get("stay_in_current_frame", CONFIG["StayInCurrentFrame"])
189
195
  if keep_frame:
190
196
  return fn(*args, **kwargs)
197
+
191
198
  err = None
192
199
  if not driver:
193
200
  driver = browser.get_current_browser()
194
201
  driver.switch_to.default_content()
202
+
195
203
  if current_frame:
196
204
  try:
197
205
  driver.switch_to.frame(current_frame)
198
- logger.debug("switching to childframe {}".format(str(fn)))
206
+ logger.debug(f"Switching to child frame {str(fn)}")
199
207
  except (StaleElementReferenceException, WebDriverException) as e:
200
208
  logger.debug(str(e))
201
209
  driver.switch_to.default_content()
202
210
  raise e
211
+
203
212
  try:
204
213
  web_element = fn(*args, **kwargs)
205
214
  except QWebElementNotFoundError as e:
206
215
  err = e
207
216
  web_element = None
217
+
208
218
  if is_valid(web_element):
209
- return web_element
219
+ if not continue_search:
220
+ return web_element
221
+ if not isinstance(web_element, tuple):
222
+ web_element = list(web_element)
223
+ # Accumulate elements if continuing search
224
+ all_elements.extend(web_element)
225
+
210
226
  start = time.time()
211
227
  timeout = CONFIG["FrameTimeout"]
212
228
  while time.time() < timeout + start:
@@ -214,65 +230,88 @@ def all_frames(fn: Callable[..., Any]) -> Callable[..., Any]:
214
230
  for frame in frames:
215
231
  web_element = search_from_frames(driver=driver, current_frame=frame)
216
232
  if is_valid(web_element):
217
- logger.debug("Found webelement = {}".format(web_element))
218
- return web_element
233
+ logger.debug(f"Found web element = {web_element}")
234
+ if not continue_search:
235
+ return web_element
236
+ if not isinstance(web_element, tuple):
237
+ web_element = list(web_element)
238
+ all_elements.extend(web_element) # Accumulate elements if continuing search
239
+
219
240
  try:
220
241
  driver.switch_to.parent_frame()
221
242
  except WebDriverException as e:
222
243
  driver.switch_to.default_content()
223
244
  raise e
245
+
224
246
  config.set_config("FrameTimeout", float(timeout + start - time.time()))
225
- logger.trace("Frame timeout: {}".format(timeout))
247
+ logger.trace(f"Frame timeout: {timeout}")
248
+
226
249
  if err:
227
250
  raise err
228
- return web_element
251
+
252
+ return all_elements if continue_search else web_element
253
+
229
254
  driver.switch_to.default_content()
230
255
  raise QWebTimeoutError("From frame decorator: Unable to locate element in given time")
231
256
 
232
- # pylint: disable=W0102
257
+ # pylint: disable=W0102, too-many-branches
233
258
  def search_from_frames_safari(
234
259
  driver: Optional[WebDriver] = None,
235
260
  current_frame: Union[Optional[WebElement], int] = None,
236
261
  parent_tree: list[Union[WebElement, int]] = [],
237
- ):
262
+ ) -> Callable[..., Any]:
263
+ # Initialize the list to store found elements if continue_search is True
264
+ all_elements = []
238
265
  keep_frame = kwargs.get("stay_in_current_frame", CONFIG["StayInCurrentFrame"])
239
266
  if keep_frame:
240
267
  return fn(*args, **kwargs)
268
+
241
269
  err = None
242
270
  if not driver:
243
271
  driver = browser.get_current_browser()
244
272
  driver.switch_to.default_content()
273
+
245
274
  if current_frame is not None:
246
275
  try:
247
276
  driver.switch_to.frame(current_frame)
248
- logger.debug("switching to childframe {}".format(str(fn)))
277
+ logger.debug("Switching to child frame {}".format(str(fn)))
249
278
  except (StaleElementReferenceException, WebDriverException) as e:
250
279
  logger.debug(str(e))
251
280
  driver.switch_to.default_content()
252
281
  raise e
282
+
253
283
  try:
254
284
  web_element = fn(*args, **kwargs)
255
285
  except QWebElementNotFoundError as e:
256
286
  err = e
257
287
  web_element = None
288
+
258
289
  if is_valid(web_element):
259
- return web_element
290
+ if not continue_search:
291
+ return web_element
292
+
293
+ if not isinstance(web_element, tuple):
294
+ web_element = list(web_element)
295
+ all_elements.extend(web_element) # Accumulate elements if continuing search
296
+
260
297
  start = time.time()
261
298
  timeout = CONFIG["FrameTimeout"]
262
299
  while time.time() < timeout + start:
263
300
  frames = fc.check_frames(driver)
264
301
  for count, frame in enumerate(frames): # pylint: disable=W0612
265
302
  parent_tree.append(count)
266
- # using count instead of frame reference due to Safari bug
267
303
  web_element = search_from_frames_safari(
268
304
  driver=driver, current_frame=count, parent_tree=parent_tree
269
305
  )
270
306
  if is_valid(web_element):
271
- logger.debug("Found webelement = {}".format(web_element))
272
- return web_element
307
+ logger.debug("Found web element = {}".format(web_element))
308
+ if not continue_search:
309
+ return web_element
310
+ if not isinstance(web_element, tuple):
311
+ web_element = list(web_element)
312
+ all_elements.extend(web_element) # Accumulate elements if continuing search
313
+
273
314
  try:
274
- # switch_to.parent_frame not working in Safari
275
- # doing moving to previuos frame "manually"
276
315
  parent_tree.pop()
277
316
  driver.switch_to.default_content()
278
317
  for f in parent_tree:
@@ -280,15 +319,21 @@ def all_frames(fn: Callable[..., Any]) -> Callable[..., Any]:
280
319
  except WebDriverException as e:
281
320
  driver.switch_to.default_content()
282
321
  raise e
322
+
283
323
  config.set_config("FrameTimeout", float(timeout + start - time.time()))
284
324
  logger.trace("Frame timeout: {}".format(timeout))
325
+
285
326
  if err:
286
327
  raise err
287
- return web_element
328
+
329
+ return all_elements if continue_search else web_element
330
+
288
331
  driver.switch_to.default_content()
289
332
  raise QWebTimeoutError("From frame decorator: Unable to locate element in given time")
290
333
 
291
- return search_from_frames_safari() if util.is_safari() else search_from_frames()
334
+ if util.is_safari():
335
+ return search_from_frames_safari()
336
+ return search_from_frames()
292
337
 
293
338
  logger.debug("wrapped = {}".format(wrapped))
294
339
  return wrapped