QWeb 3.7.0__tar.gz → 3.7.2__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.
- {qweb-3.7.0 → qweb-3.7.2}/PKG-INFO +1 -1
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/_version.py +3 -3
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/browser/__init__.py +16 -7
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/config_defaults.py +4 -4
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/frame.py +8 -3
- qweb-3.7.2/QWeb/internal/javascript.py +205 -0
- qweb-3.7.2/QWeb/internal/js/find_text_from_textnodes.js +21 -0
- qweb-3.7.2/QWeb/internal/js/get_all_dropdown_elements_shadow_dom.js +14 -0
- qweb-3.7.2/QWeb/internal/js/get_all_frames_from_shadow_dom.js +14 -0
- qweb-3.7.2/QWeb/internal/js/get_all_input_elements_from_shadow_dom.js +14 -0
- qweb-3.7.2/QWeb/internal/js/get_by_attributes.js +28 -0
- qweb-3.7.2/QWeb/internal/js/get_by_label.js +72 -0
- qweb-3.7.2/QWeb/internal/js/get_childnodes.js +18 -0
- qweb-3.7.2/QWeb/internal/js/get_clickable.js +27 -0
- qweb-3.7.2/QWeb/internal/js/get_clickable_from_shadow_dom.js +33 -0
- qweb-3.7.2/QWeb/internal/js/get_item_elements_from_shadow_dom.js +15 -0
- qweb-3.7.2/QWeb/internal/js/get_parent_list.js +19 -0
- qweb-3.7.2/QWeb/internal/js/get_recursive_walk.js +23 -0
- qweb-3.7.2/QWeb/internal/js/get_text_elements_from_shadow_dom.js +26 -0
- qweb-3.7.2/QWeb/internal/js/get_visibility.js +22 -0
- qweb-3.7.2/QWeb/internal/js/highlight_element.js +30 -0
- qweb-3.7.2/QWeb/internal/js/install_monitor.js +83 -0
- qweb-3.7.2/QWeb/internal/js/spinner_busy.js +77 -0
- qweb-3.7.2/QWeb/internal/js/toast_notification.js +86 -0
- qweb-3.7.2/QWeb/internal/js/wait_status_lite.js +30 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/search_strategy.py +31 -4
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/xhr.py +9 -129
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/browser.py +70 -20
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/window.py +119 -38
- {qweb-3.7.0 → qweb-3.7.2}/QWeb.egg-info/PKG-INFO +1 -1
- {qweb-3.7.0 → qweb-3.7.2}/QWeb.egg-info/SOURCES.txt +19 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb.egg-info/top_level.txt +1 -0
- {qweb-3.7.0 → qweb-3.7.2}/pyproject.toml +3 -0
- qweb-3.7.0/QWeb/internal/javascript.py +0 -707
- {qweb-3.7.0 → qweb-3.7.2}/LICENSE +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/MANIFEST.in +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/__init__.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/__main__.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/custom_config.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/__init__.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/actions.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/ajax.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/alert.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/blocks.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/browser/android.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/browser/bs_desktop.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/browser/bs_mobile.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/browser/chrome.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/browser/edge.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/browser/firefox.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/browser/safari.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/checkbox.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/config.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/cookies.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/decorators.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/download.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/dragdrop.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/dropdown.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/element.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/exceptions.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/file.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/frame_checker.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/icon.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/input_.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/input_handler.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/lists.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/meas.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/platform.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/screenshot.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/secrets.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/table.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/text.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/user.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/util.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/internal/window.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/__init__.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/ajax.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/alert.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/blocks.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/checkbox.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/config.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/cookies.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/debug.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/download.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/dragdrop.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/dropdown.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/element.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/file.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/frame.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/icon.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/input_.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/javascript.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/lists.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/mouse.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/screenshot.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/search_strategy.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/table.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb/keywords/text.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb.egg-info/dependency_links.txt +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/QWeb.egg-info/requires.txt +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/README.md +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/example/CustomerLibrary/CustomerLib.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/example/CustomerLibrary/decorators.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/setup.cfg +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/setup.py +0 -0
- {qweb-3.7.0 → qweb-3.7.2}/versioneer.py +0 -0
|
@@ -8,11 +8,11 @@ import json
|
|
|
8
8
|
|
|
9
9
|
version_json = '''
|
|
10
10
|
{
|
|
11
|
-
"date": "2025-
|
|
11
|
+
"date": "2025-11-17T09:34:11+0200",
|
|
12
12
|
"dirty": false,
|
|
13
13
|
"error": null,
|
|
14
|
-
"full-revisionid": "
|
|
15
|
-
"version": "3.7.
|
|
14
|
+
"full-revisionid": "352e83ab8eb0b91a0904d3d1d3b743640c30d034",
|
|
15
|
+
"version": "3.7.2"
|
|
16
16
|
}
|
|
17
17
|
''' # END VERSION_JSON
|
|
18
18
|
|
|
@@ -95,25 +95,34 @@ def get_current_browser() -> WebDriver:
|
|
|
95
95
|
return _current_browser
|
|
96
96
|
|
|
97
97
|
|
|
98
|
-
def set_current_browser(
|
|
98
|
+
def set_current_browser(target: Union[int, str]) -> None:
|
|
99
99
|
# pylint: disable=global-statement
|
|
100
100
|
global _current_browser
|
|
101
101
|
|
|
102
|
-
if str(
|
|
103
|
-
if int(
|
|
102
|
+
if str(target).isdigit():
|
|
103
|
+
if int(target) == 0:
|
|
104
104
|
raise QWebValueError("SwitchBrowser index starts at 1.")
|
|
105
105
|
|
|
106
|
-
i = int(
|
|
106
|
+
i = int(target) - 1
|
|
107
107
|
|
|
108
108
|
if i < len(_open_browsers):
|
|
109
109
|
_current_browser = _open_browsers[i]
|
|
110
110
|
else:
|
|
111
|
-
raise QWebDriverError(f"Tried to select browser with index {
|
|
111
|
+
raise QWebDriverError(f"Tried to select browser with index {target} but there are \
|
|
112
112
|
{len(_open_browsers)} browsers open")
|
|
113
|
-
elif str(
|
|
113
|
+
elif str(target) == "NEW":
|
|
114
114
|
_current_browser = _open_browsers[-1]
|
|
115
115
|
else:
|
|
116
|
-
|
|
116
|
+
# Try to find a browser by open page title. If multiple matches, first one is selected
|
|
117
|
+
for browser in _open_browsers:
|
|
118
|
+
try:
|
|
119
|
+
if target == browser.title:
|
|
120
|
+
_current_browser = browser
|
|
121
|
+
return
|
|
122
|
+
except Exception: # pylint: disable=broad-except
|
|
123
|
+
# Browser might be closed already etc.
|
|
124
|
+
continue
|
|
125
|
+
raise QWebValueError(f'No open browser with title "{target}" found.')
|
|
117
126
|
|
|
118
127
|
|
|
119
128
|
def get_open_browsers() -> list[WebDriver]:
|
|
@@ -48,7 +48,7 @@ CONFIG_DEFAULTS: dict[str, Any] = {
|
|
|
48
48
|
"LogScreenshot": (True, util.par2bool),
|
|
49
49
|
"SearchDirection": ("closest", SearchStrategies.search_direction_validation),
|
|
50
50
|
"CheckInputValue": (False, util.par2bool),
|
|
51
|
-
"DefaultTimeout": ("10s", SearchStrategies.
|
|
51
|
+
"DefaultTimeout": ("10s", SearchStrategies.timeout_validator),
|
|
52
52
|
"XHRTimeout": ("30", SearchStrategies.xhr_timeout_validation),
|
|
53
53
|
"DefaultDocument": (True, util.par2bool),
|
|
54
54
|
"InputHandler": ("selenium", util.set_input_handler),
|
|
@@ -87,12 +87,12 @@ CONFIG_DEFAULTS: dict[str, Any] = {
|
|
|
87
87
|
"HandleAlerts": (True, util.par2bool),
|
|
88
88
|
"BlindReturn": (False, util.par2bool),
|
|
89
89
|
"Headless": (False, util.par2bool),
|
|
90
|
-
"Delay": ("0s", SearchStrategies.
|
|
90
|
+
"Delay": ("0s", SearchStrategies.timeout_validator),
|
|
91
91
|
"RunBefore": (None, util.validate_run_before),
|
|
92
|
-
"RetryInterval": ("5s", SearchStrategies.
|
|
92
|
+
"RetryInterval": ("5s", SearchStrategies.timeout_validator),
|
|
93
93
|
"RetryError": (None, None),
|
|
94
94
|
"StayInCurrentFrame": (False, util.par2bool),
|
|
95
|
-
"FrameTimeout": ("10s", SearchStrategies.
|
|
95
|
+
"FrameTimeout": ("10s", SearchStrategies.timeout_validator),
|
|
96
96
|
"AllTextNodes": (False, util.par2bool),
|
|
97
97
|
"OSScreenshots": (False, util.par2bool),
|
|
98
98
|
"RetinaDisplay": (util.is_retina(), util.par2bool),
|
|
@@ -78,16 +78,21 @@ def wait_page_loaded() -> None:
|
|
|
78
78
|
raise QWebBrowserError(e) from e
|
|
79
79
|
driver.switch_to.default_content()
|
|
80
80
|
timeout = CONFIG["XHRTimeout"]
|
|
81
|
-
|
|
82
|
-
return
|
|
81
|
+
|
|
83
82
|
try:
|
|
84
83
|
strategy = CONFIG["WaitStrategy"]
|
|
85
84
|
if strategy.lower() == "legacy":
|
|
86
85
|
logger.debug("Using legacy jQuery-based waiter")
|
|
86
|
+
if timeout.lower() == "none":
|
|
87
|
+
return
|
|
87
88
|
xhr.wait_xhr_legacy(timestr_to_secs(timeout))
|
|
88
89
|
else:
|
|
89
90
|
logger.debug("Using enhanced waiter (network/spinner/render)")
|
|
90
|
-
|
|
91
|
+
if timeout.lower() == "none":
|
|
92
|
+
# Use default timeout, but skip network idle check
|
|
93
|
+
xhr.wait_xhr(skip_network=True)
|
|
94
|
+
else:
|
|
95
|
+
xhr.wait_xhr(timestr_to_secs(timeout))
|
|
91
96
|
|
|
92
97
|
except (WebDriverException, QWebDriverError) as e:
|
|
93
98
|
logger.debug(f"Unable to check network requests due error: {e}")
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# --------------------------
|
|
3
|
+
# Copyright © 2014 - Qentinel Group.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
# ---------------------------
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
import importlib.resources
|
|
19
|
+
from typing import Any, Union
|
|
20
|
+
from selenium.webdriver.remote.webelement import WebElement
|
|
21
|
+
from QWeb.internal import browser
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def load_js(filename):
|
|
25
|
+
|
|
26
|
+
# Adjust the package path as needed
|
|
27
|
+
return (importlib.resources.files('QWeb.internal.js')
|
|
28
|
+
.joinpath(filename)
|
|
29
|
+
.read_text(encoding='utf-8'))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# Preload JS files at import
|
|
33
|
+
_TOAST_NOTIFICATION_JS = load_js('toast_notification.js')
|
|
34
|
+
_GET_VISIBILITY_JS = load_js('get_visibility.js')
|
|
35
|
+
_HIGHLIGHT_ELEMENT_JS = load_js('highlight_element.js')
|
|
36
|
+
_GET_BY_ATTRIBUTES_JS = load_js('get_by_attributes.js')
|
|
37
|
+
_GET_CHILDNODES_JS = load_js('get_childnodes.js')
|
|
38
|
+
_GET_BY_LABEL_JS = load_js('get_by_label.js')
|
|
39
|
+
_GET_PARENT_LIST_JS = load_js('get_parent_list.js')
|
|
40
|
+
_FIND_TEXT_FROM_TEXTNODES_JS = load_js('find_text_from_textnodes.js')
|
|
41
|
+
_GET_CLICKABLE_JS = load_js('get_clickable.js')
|
|
42
|
+
_GET_RECURSIVE_WALK_JS = load_js('get_recursive_walk.js')
|
|
43
|
+
_GET_TEXT_ELEMENTS_FROM_SHADOW_DOM_JS = load_js('get_text_elements_from_shadow_dom.js')
|
|
44
|
+
_GET_CLICKABLE_FROM_SHADOW_DOM_JS = load_js('get_clickable_from_shadow_dom.js')
|
|
45
|
+
_GET_ALL_FRAMES_FROM_SHADOW_DOM_JS = load_js('get_all_frames_from_shadow_dom.js')
|
|
46
|
+
_GET_ALL_INPUT_ELEMENTS_FROM_SHADOW_DOM_JS = load_js('get_all_input_elements_from_shadow_dom.js')
|
|
47
|
+
_GET_ALL_DROPDOWN_ELEMENTS_FROM_SHADOW_DOM_JS = load_js('get_all_dropdown_elements_shadow_dom.js')
|
|
48
|
+
_GET_ITEM_ELEMENTS_FROM_SHADOW_DOM_JS = load_js('get_item_elements_from_shadow_dom.js')
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def execute_javascript(script: str, *args) -> Any:
|
|
52
|
+
"""Run given javascript on current window.
|
|
53
|
+
|
|
54
|
+
Parameters
|
|
55
|
+
----------
|
|
56
|
+
script : str
|
|
57
|
+
Javascript code.
|
|
58
|
+
*args : WebElement
|
|
59
|
+
WebElement object that is stored in to variable "arguments" which is
|
|
60
|
+
an array in javascript. Check example.
|
|
61
|
+
|
|
62
|
+
Returns
|
|
63
|
+
-------
|
|
64
|
+
str
|
|
65
|
+
Output of the executed javascript.
|
|
66
|
+
|
|
67
|
+
Example
|
|
68
|
+
-------
|
|
69
|
+
execute_javascript('arguments[0].setAttribute("style", "background-color:yellow")', web_element)
|
|
70
|
+
"""
|
|
71
|
+
driver = browser.get_current_browser()
|
|
72
|
+
return driver.execute_script(script, *args)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def get_visibility(web_elements: list[WebElement]) -> list[dict]:
|
|
76
|
+
"""Return web element objects (using external JS file, preloaded)."""
|
|
77
|
+
js = _GET_VISIBILITY_JS
|
|
78
|
+
return execute_javascript(js, web_elements)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def highlight_element(
|
|
82
|
+
element: WebElement, draw_only: bool, flash_border: bool = False, color: str = "blue"
|
|
83
|
+
) -> None:
|
|
84
|
+
"""Highlight borders for given web element (using external JS file, preloaded)."""
|
|
85
|
+
js = _HIGHLIGHT_ELEMENT_JS
|
|
86
|
+
execute_javascript(js, element, draw_only, flash_border, color)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def get_by_attributes(
|
|
90
|
+
elements: list[WebElement], locator: str, partial_match: bool
|
|
91
|
+
) -> dict[str, list[WebElement]]:
|
|
92
|
+
"""Return web element by its attribute value (using external JS file, preloaded)."""
|
|
93
|
+
js = _GET_BY_ATTRIBUTES_JS
|
|
94
|
+
return execute_javascript(js, elements, locator.replace("'", "\\'"), partial_match)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def get_all_elements(css: str) -> list[WebElement]:
|
|
98
|
+
"""Return all web elements for given css-locator.
|
|
99
|
+
Parameters
|
|
100
|
+
----------
|
|
101
|
+
css : selector
|
|
102
|
+
For example: p,h1,h2,h3,input
|
|
103
|
+
|
|
104
|
+
Returns
|
|
105
|
+
-------
|
|
106
|
+
list of web elements.
|
|
107
|
+
"""
|
|
108
|
+
return execute_javascript("return document.querySelectorAll('{}')".format(css))
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def get_childnodes(
|
|
112
|
+
locator_element: WebElement, css: str, level: int = 3, traverse: bool = True
|
|
113
|
+
) -> list[WebElement]:
|
|
114
|
+
"""Find matching childs for given locator element (using external JS file, preloaded)."""
|
|
115
|
+
js = _GET_CHILDNODES_JS
|
|
116
|
+
return execute_javascript(js, locator_element, css, level, traverse)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def get_by_label(
|
|
120
|
+
locator_text: str, css: str, level: int, partial_match: bool
|
|
121
|
+
) -> dict[str, list[WebElement]]:
|
|
122
|
+
"""Find element based on its label (using external JS file, preloaded)."""
|
|
123
|
+
js = _GET_BY_LABEL_JS
|
|
124
|
+
return execute_javascript(js, locator_text.replace("'", "\\'"), css, level, partial_match)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def get_parent_list(
|
|
128
|
+
locator_element: Union[WebElement, str], css: str
|
|
129
|
+
) -> Union[WebElement, list[WebElement]]:
|
|
130
|
+
"""Get parent list for web element (using external JS file, preloaded)."""
|
|
131
|
+
js = _GET_PARENT_LIST_JS
|
|
132
|
+
return execute_javascript(js, locator_element, css)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def find_text_from_textnodes(text: str, **kwargs) -> list[WebElement]:
|
|
136
|
+
"""Find elements whose textContent matches to preferred text
|
|
137
|
+
(using external JS file, preloaded)."""
|
|
138
|
+
js = _FIND_TEXT_FROM_TEXTNODES_JS
|
|
139
|
+
doc = "html"
|
|
140
|
+
partial = kwargs.get("partial_match")
|
|
141
|
+
return execute_javascript(js, text, doc, partial)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def get_clickable(locator: str) -> list[WebElement]:
|
|
145
|
+
"""Find clickable elements matching the locator (using external JS file, preloaded)."""
|
|
146
|
+
js = _GET_CLICKABLE_JS
|
|
147
|
+
return execute_javascript(js, locator)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def get_text_elements_from_shadow_dom(locator: str, partial: bool) -> list[WebElement]:
|
|
151
|
+
"""Find elements in shadow DOM whose textContent matches to preferred text (using
|
|
152
|
+
external JS file, preloaded)."""
|
|
153
|
+
js = _GET_RECURSIVE_WALK_JS + "\n" + _GET_TEXT_ELEMENTS_FROM_SHADOW_DOM_JS
|
|
154
|
+
return execute_javascript(js, locator, partial)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def get_clickable_from_shadow_dom(locator: str, partial: bool) -> list[WebElement]:
|
|
158
|
+
"""Find clickable elements in shadow DOM matching the locator
|
|
159
|
+
(using external JS file, preloaded)."""
|
|
160
|
+
js = _GET_RECURSIVE_WALK_JS + "\n" + _GET_CLICKABLE_FROM_SHADOW_DOM_JS
|
|
161
|
+
return execute_javascript(js, locator, partial)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def get_all_frames_from_shadow_dom() -> list[WebElement]:
|
|
165
|
+
"""Find all iframe and frame elements in shadow DOM (using external JS file, preloaded)."""
|
|
166
|
+
js = _GET_RECURSIVE_WALK_JS + "\n" + _GET_ALL_FRAMES_FROM_SHADOW_DOM_JS
|
|
167
|
+
return execute_javascript(js)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def get_all_input_elements_from_shadow_dom() -> list[WebElement]:
|
|
171
|
+
"""Find all input and textarea elements in shadow DOM (using external JS file, preloaded)."""
|
|
172
|
+
js = _GET_RECURSIVE_WALK_JS + "\n" + _GET_ALL_INPUT_ELEMENTS_FROM_SHADOW_DOM_JS
|
|
173
|
+
return execute_javascript(js)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def get_all_dropdown_elements_from_shadow_dom() -> list[WebElement]:
|
|
177
|
+
"""Find all select elements in shadow DOM (using external JS file, preloaded)."""
|
|
178
|
+
js = _GET_RECURSIVE_WALK_JS + "\n" + _GET_ALL_DROPDOWN_ELEMENTS_FROM_SHADOW_DOM_JS
|
|
179
|
+
return execute_javascript(js)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def get_item_elements_from_shadow_dom(tag: str) -> list[WebElement]:
|
|
183
|
+
"""Find item elements in shadow DOM matching supported tags or a given tag
|
|
184
|
+
(using external JS file, preloaded)."""
|
|
185
|
+
js = _GET_RECURSIVE_WALK_JS + "\n" + _GET_ITEM_ELEMENTS_FROM_SHADOW_DOM_JS
|
|
186
|
+
return execute_javascript(js, tag)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def create_toast_notification(message: str, level: str = "info", position: str = "center",
|
|
190
|
+
font_size: int = 18,
|
|
191
|
+
heading: str = "Test Automation Notification", timeout: int = 3):
|
|
192
|
+
"""Display toast notification in the browser via JavaScript (external file, preloaded)."""
|
|
193
|
+
js = _TOAST_NOTIFICATION_JS
|
|
194
|
+
js_call = (
|
|
195
|
+
f"createToastNotification(\n"
|
|
196
|
+
f" {message!r},\n"
|
|
197
|
+
f" {level!r},\n"
|
|
198
|
+
f" {position!r},\n"
|
|
199
|
+
f" {font_size},\n"
|
|
200
|
+
f" {heading!r},\n"
|
|
201
|
+
f" {timeout}\n"
|
|
202
|
+
f")"
|
|
203
|
+
)
|
|
204
|
+
full_js = js + "\n" + js_call
|
|
205
|
+
return execute_javascript(full_js)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// find_text_from_textnodes.js
|
|
2
|
+
// Finds elements whose textContent matches or includes the given text
|
|
3
|
+
|
|
4
|
+
function getTextNodes(text, tag, partial) {
|
|
5
|
+
let mainDoc = document.querySelector(tag);
|
|
6
|
+
const iterator = document.createNodeIterator(mainDoc, NodeFilter.SHOW_TEXT);
|
|
7
|
+
const textNodes = [];
|
|
8
|
+
let currentNode;
|
|
9
|
+
while ((currentNode = iterator.nextNode())) {
|
|
10
|
+
if (currentNode.textContent.trim() === text) {
|
|
11
|
+
textNodes.push(currentNode.parentElement);
|
|
12
|
+
continue;
|
|
13
|
+
} else if (partial && currentNode.textContent.trim().includes(text)) {
|
|
14
|
+
textNodes.push(currentNode.parentElement);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return textNodes;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Entrypoint for Selenium execute_script
|
|
21
|
+
return getTextNodes(arguments[0], arguments[1], arguments[2]);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// get_all_dropdown_elements_from_shadow_dom.js
|
|
2
|
+
// Finds all select elements in shadow DOM
|
|
3
|
+
// Assumes recursiveWalk (get_recursive_walk.js) is defined in the context
|
|
4
|
+
function find_all_select_elements_from_shadow_dom() {
|
|
5
|
+
var results = [];
|
|
6
|
+
var elem = recursiveWalk(document.body, function(node) {
|
|
7
|
+
if (node.tagName == "SELECT") {
|
|
8
|
+
results.push(node);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
return results;
|
|
12
|
+
}
|
|
13
|
+
// Entrypoint for Selenium execute_script
|
|
14
|
+
return find_all_select_elements_from_shadow_dom(arguments[0]);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// get_all_frames_from_shadow_dom.js
|
|
2
|
+
// Finds all iframe and frame elements in shadow DOM
|
|
3
|
+
// Assumes recursiveWalk (get_recursive_walk.js) is defined in the context
|
|
4
|
+
function find_all_frames_from_shadow_dom() {
|
|
5
|
+
var results = [];
|
|
6
|
+
var elem = recursiveWalk(document.body, function(node) {
|
|
7
|
+
if (node.tagName == "IFRAME" || node.tagName == "FRAME") {
|
|
8
|
+
results.push(node);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
return results;
|
|
12
|
+
}
|
|
13
|
+
// Entrypoint for Selenium execute_script
|
|
14
|
+
return find_all_frames_from_shadow_dom(arguments[0]);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// get_all_input_elements_from_shadow_dom.js
|
|
2
|
+
// Finds all input and textarea elements in shadow DOM
|
|
3
|
+
// Assumes recursiveWalk (get_recursive_walk.js) is defined in the context
|
|
4
|
+
function find_all_input_elements_from_shadow_dom() {
|
|
5
|
+
var results = [];
|
|
6
|
+
var elem = recursiveWalk(document.body, function(node) {
|
|
7
|
+
if (node.tagName == "INPUT" || node.tagName == "TEXTAREA") {
|
|
8
|
+
results.push(node);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
return results;
|
|
12
|
+
}
|
|
13
|
+
// Entrypoint for Selenium execute_script
|
|
14
|
+
return find_all_input_elements_from_shadow_dom(arguments[0]);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// get_by_attributes.js
|
|
2
|
+
// Returns elements matching attribute value, with full and partial matches
|
|
3
|
+
|
|
4
|
+
function getByAttributes(elems, locator, partial) {
|
|
5
|
+
var matches = {};
|
|
6
|
+
var full = [];
|
|
7
|
+
var part = [];
|
|
8
|
+
for (var i = 0; i < elems.length; i++) {
|
|
9
|
+
var attrs = elems[i].attributes;
|
|
10
|
+
if (attrs == null) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
for (var j = 0; j < attrs.length; j++) {
|
|
14
|
+
if (attrs[j].value.trim() == locator) {
|
|
15
|
+
full.push(elems[i]);
|
|
16
|
+
break;
|
|
17
|
+
} else if (partial && attrs[j].value.includes(locator)) {
|
|
18
|
+
part.push(elems[i]);
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
matches = { full: full, partial: part };
|
|
24
|
+
return matches;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Entrypoint for Selenium execute_script
|
|
28
|
+
return getByAttributes(arguments[0], arguments[1], arguments[2]);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// get_by_label.js
|
|
2
|
+
// Finds elements based on their label, supporting for-attribute and DOM traversal
|
|
3
|
+
|
|
4
|
+
function traverseLabel(locator, selector, level) {
|
|
5
|
+
if (locator.querySelectorAll(selector).length > 0) {
|
|
6
|
+
return locator.querySelectorAll(selector);
|
|
7
|
+
} else {
|
|
8
|
+
for (var i = 0; i < level; i++) {
|
|
9
|
+
locator = locator.parentNode;
|
|
10
|
+
if (locator.querySelectorAll(selector).length > 0)
|
|
11
|
+
return locator.querySelectorAll(selector);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getByFor(needle, haystack) {
|
|
18
|
+
for (var i = 0; i < haystack.length; i++) {
|
|
19
|
+
if (haystack[i].hasAttribute('id') && haystack[i].getAttribute('id') == needle) {
|
|
20
|
+
return haystack[i];
|
|
21
|
+
}
|
|
22
|
+
if (haystack[i].hasAttribute('name') && haystack[i].getAttribute('name') == needle) {
|
|
23
|
+
return haystack[i];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getByLabel(locator, selector, level, partial) {
|
|
30
|
+
var elems = document.querySelectorAll('label');
|
|
31
|
+
var haystack = document.querySelectorAll(selector);
|
|
32
|
+
var matches = {};
|
|
33
|
+
var full_matches = [];
|
|
34
|
+
var part_with_for = [];
|
|
35
|
+
var part_matches = [];
|
|
36
|
+
for (var i = 0; i < elems.length; i++) {
|
|
37
|
+
if (elems[i].hasAttribute('for') && elems[i].innerText.trim() === locator) {
|
|
38
|
+
var needle = elems[i].getAttribute('for');
|
|
39
|
+
var target = getByFor(needle, haystack);
|
|
40
|
+
if (target) {
|
|
41
|
+
full_matches.push(target);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
} else if (elems[i].innerText.trim() === locator) {
|
|
45
|
+
var target = traverseLabel(elems[i], selector, level)[0];
|
|
46
|
+
if (target) {
|
|
47
|
+
full_matches.push(target);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (partial === true) {
|
|
52
|
+
if (elems[i].hasAttribute('for') && elems[i].innerText.trim().includes(locator)) {
|
|
53
|
+
var needle = elems[i].getAttribute('for');
|
|
54
|
+
var target = getByFor(needle, haystack);
|
|
55
|
+
if (target) {
|
|
56
|
+
part_with_for.push(target);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
} else if (elems[i].innerText.trim().includes(locator)) {
|
|
60
|
+
var target = traverseLabel(elems[i], selector, level)[0];
|
|
61
|
+
if (target) {
|
|
62
|
+
part_matches.push(target);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
matches = { full: full_matches.concat(part_with_for), partial: part_matches };
|
|
68
|
+
return matches;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Entrypoint for Selenium execute_script
|
|
72
|
+
return getByLabel(arguments[0], arguments[1], arguments[2], arguments[3]);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// get_childnodes.js
|
|
2
|
+
// Finds matching child nodes for a given locator element, with optional upward traversal
|
|
3
|
+
|
|
4
|
+
function getChildNodes(locator, selector, level, traverse) {
|
|
5
|
+
if (locator.querySelectorAll(selector).length > 0) {
|
|
6
|
+
return locator.querySelectorAll(selector);
|
|
7
|
+
} else if (traverse) {
|
|
8
|
+
for (var i = 0; i < level; i++) {
|
|
9
|
+
locator = locator.parentNode;
|
|
10
|
+
if (locator.querySelectorAll(selector).length > 0)
|
|
11
|
+
return locator.querySelectorAll(selector);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Entrypoint for Selenium execute_script
|
|
18
|
+
return getChildNodes(arguments[0], arguments[1], arguments[2], arguments[3]);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// get_clickable.js
|
|
2
|
+
// Finds clickable elements matching the locator (full and partial matches)
|
|
3
|
+
|
|
4
|
+
function getClickable(locator) {
|
|
5
|
+
var full = [];
|
|
6
|
+
var partial = [];
|
|
7
|
+
var candidates = [];
|
|
8
|
+
var text = "";
|
|
9
|
+
var elems = document.querySelectorAll('button, a, label, *[type="submit"], *[type="button"], *[type="reset"], li[data-value], input[type="radio"], *[role="tab"], *[role="button"], *[ng-click], *[data-ng-click],[href]');
|
|
10
|
+
for (var i = 0; i < elems.length; i++) {
|
|
11
|
+
if (elems[i].tagName.toLowerCase() === 'input') {
|
|
12
|
+
text = elems[i].value;
|
|
13
|
+
} else {
|
|
14
|
+
text = elems[i].innerText;
|
|
15
|
+
}
|
|
16
|
+
if (text.trim() === locator) {
|
|
17
|
+
full.push(elems[i]);
|
|
18
|
+
} else if (text.trim().toLowerCase() === locator.toLowerCase()) {
|
|
19
|
+
partial.push(elems[i]);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
candidates = full.concat(partial);
|
|
23
|
+
return candidates;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Entrypoint for Selenium execute_script
|
|
27
|
+
return getClickable(arguments[0]);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// get_clickable_from_shadow_dom.js
|
|
2
|
+
// Finds clickable elements in shadow DOM matching the locator (full and partial matches)
|
|
3
|
+
// Assumes recursiveWalk (get_recursive_walk.js) is defined in the context
|
|
4
|
+
function find_clickable_from_shadow_dom(text, partial) {
|
|
5
|
+
var results = [];
|
|
6
|
+
var full = [];
|
|
7
|
+
var parts = [];
|
|
8
|
+
var clickable_types = ["button", "reset", "submit"];
|
|
9
|
+
var elem = recursiveWalk(document.body, function(node) {
|
|
10
|
+
try {
|
|
11
|
+
if ((node.getAttribute('onclick')!=null) ||
|
|
12
|
+
(node.getAttribute('href')!=null) ||
|
|
13
|
+
(node.getAttribute('role')=='button') ||
|
|
14
|
+
(clickable_types.includes(node.getAttribute('type')))) {
|
|
15
|
+
var nodetext;
|
|
16
|
+
if (node.tagName.toLowerCase() == "input" && node.type("radio")) {
|
|
17
|
+
nodetext = node.value;
|
|
18
|
+
} else {
|
|
19
|
+
nodetext = node.innerText;
|
|
20
|
+
}
|
|
21
|
+
if(nodetext.trim() === text) {
|
|
22
|
+
full.push(node);
|
|
23
|
+
} else if (partial && nodetext.trim().includes(text)) {
|
|
24
|
+
parts.push(node);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
} catch(ex) {}
|
|
28
|
+
});
|
|
29
|
+
results = full.concat(parts);
|
|
30
|
+
return results;
|
|
31
|
+
}
|
|
32
|
+
// Entrypoint for Selenium execute_script
|
|
33
|
+
return find_clickable_from_shadow_dom(arguments[0], arguments[1]);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// get_item_elements_from_shadow_dom.js
|
|
2
|
+
// Finds item elements in shadow DOM matching supported tags or a given tag
|
|
3
|
+
// Assumes recursiveWalk (get_recursive_walk.js) is defined in the context
|
|
4
|
+
function find_item_elements_from_shadow_dom(tag) {
|
|
5
|
+
var results = [];
|
|
6
|
+
var supported_tags = tag === null ? ["A", "SPAN", "IMG", "LI", "H1", "H2", "H3", "H4", "H5", "H6", "DIV", "SVG", "P", "BUTTON", "INPUT", "TEXTAREA"] : [tag.toUpperCase()];
|
|
7
|
+
var elem = recursiveWalk(document.body, function(node) {
|
|
8
|
+
if (supported_tags.includes(node.tagName)) {
|
|
9
|
+
results.push(node);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
return results;
|
|
13
|
+
}
|
|
14
|
+
// Entrypoint for Selenium execute_script
|
|
15
|
+
return find_item_elements_from_shadow_dom(arguments[0], arguments[1]);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// get_parent_list.js
|
|
2
|
+
// Gets parent list for a web element, with special handling for list tags
|
|
3
|
+
|
|
4
|
+
function getParentList(locator, css) {
|
|
5
|
+
var list_tags = ["ul", "ol", "dl", "UL", "OL", "DL"];
|
|
6
|
+
if (list_tags.includes(css)) {
|
|
7
|
+
if ((locator.parentNode.tagName === "UL" || locator.parentNode.tagName === "OL" || locator.parentNode.tagName === "DL") && locator.parentNode.parentNode.tagName === css.toUpperCase()) {
|
|
8
|
+
return locator.parentNode.parentNode;
|
|
9
|
+
} else if (locator.parentNode.parentNode.parentNode.tagName === css.toUpperCase()) {
|
|
10
|
+
return locator.parentNode.parentNode.parentNode;
|
|
11
|
+
}
|
|
12
|
+
} else {
|
|
13
|
+
return locator.parentNode.parentNode;
|
|
14
|
+
}
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Entrypoint for Selenium execute_script
|
|
19
|
+
return getParentList(arguments[0], arguments[1]);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// get_recursive_walk.js
|
|
2
|
+
// Defines recursiveWalk as a global function for traversing DOM and shadow DOM
|
|
3
|
+
|
|
4
|
+
function recursiveWalk(node, func) {
|
|
5
|
+
var done = func(node);
|
|
6
|
+
if (done) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
if ('shadowRoot' in node && node.shadowRoot) {
|
|
10
|
+
var done = recursiveWalk(node.shadowRoot, func);
|
|
11
|
+
if (done) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
node = node.firstChild;
|
|
16
|
+
while (node) {
|
|
17
|
+
var done = recursiveWalk(node, func);
|
|
18
|
+
if (done) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
node = node.nextSibling;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// get_text_elements_from_shadow_dom.js
|
|
2
|
+
// Finds elements in shadow DOM whose textContent matches or includes the given text
|
|
3
|
+
|
|
4
|
+
// Assumes recursiveWalk (get_recursive_walk.js) is defined in the context
|
|
5
|
+
function find_text_from_shadow_dom(text, partial) {
|
|
6
|
+
var results = [];
|
|
7
|
+
var unsupported_tags = ["script", "#document-fragment"];
|
|
8
|
+
var elem = recursiveWalk(document.body, function(node) {
|
|
9
|
+
if (node.textContent && node.textContent.replace(/\u00a0/g, ' ').includes(text) && !unsupported_tags.includes(node.nodeName.toLowerCase())) {
|
|
10
|
+
var nodetext = [].reduce.call(node.childNodes, function(a, b) { return a + (b.nodeType === 3 ? b.textContent.trim() : ''); }, '');
|
|
11
|
+
nodetext = nodetext.replace(/\u00a0/g, ' ');
|
|
12
|
+
if (nodetext == text) {
|
|
13
|
+
results.push(node);
|
|
14
|
+
} else if (partial && nodetext.includes(text)) {
|
|
15
|
+
results.push(node);
|
|
16
|
+
}
|
|
17
|
+
} else if (node.placeholder === text || node.value === text) {
|
|
18
|
+
results.push(node);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return results;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Entrypoint for Selenium execute_script
|
|
25
|
+
// This file expects recursiveWalk to be defined in the context
|
|
26
|
+
return find_text_from_shadow_dom(arguments[0], arguments[1]);
|