automation_model 1.0.4 → 1.0.5
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.
- package/bin/stable_browser.js +22 -8
- package/package.json +1 -1
package/bin/stable_browser.js
CHANGED
|
@@ -9,17 +9,29 @@ class StableBrowser {
|
|
|
9
9
|
timeout: 60000,
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
|
-
async _locate(selector) {
|
|
12
|
+
async _locate(selector, scope) {
|
|
13
13
|
if (typeof selector === "object") {
|
|
14
14
|
try {
|
|
15
|
+
if (Array.isArray(selector)) {
|
|
16
|
+
let currentScope = scope;
|
|
17
|
+
|
|
18
|
+
for (let i = 0; i < selector.length; i++) {
|
|
19
|
+
currentScope = await this._locate(
|
|
20
|
+
selector[i],
|
|
21
|
+
currentScope
|
|
22
|
+
).first();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
15
25
|
if (selector.css) {
|
|
16
|
-
return await
|
|
26
|
+
return await scope.locator(selector.css).first();
|
|
17
27
|
}
|
|
18
28
|
if (selector.role) {
|
|
19
|
-
return await
|
|
29
|
+
return await scope
|
|
30
|
+
.getByRole(selector.role[0], selector.role[1])
|
|
31
|
+
.first();
|
|
20
32
|
}
|
|
21
33
|
if (selector.text) {
|
|
22
|
-
return await
|
|
34
|
+
return await scope.getByText(selector.text).first();
|
|
23
35
|
}
|
|
24
36
|
throw new Error(`Unknown locator type ${type}`);
|
|
25
37
|
} catch (e) {
|
|
@@ -28,17 +40,19 @@ class StableBrowser {
|
|
|
28
40
|
}
|
|
29
41
|
|
|
30
42
|
if (selector.startsWith("TEXT=")) {
|
|
31
|
-
return await this.page
|
|
43
|
+
return await this.page
|
|
44
|
+
.getByText(selector.substring("TEXT=".length))
|
|
45
|
+
.first();
|
|
32
46
|
} else {
|
|
33
|
-
return await this.page.locator(selector);
|
|
47
|
+
return await this.page.locator(selector).first();
|
|
34
48
|
}
|
|
35
49
|
}
|
|
36
50
|
|
|
37
51
|
async click(selector) {
|
|
38
|
-
(await this._locate(selector)).click();
|
|
52
|
+
(await this._locate(selector, this.page)).click();
|
|
39
53
|
}
|
|
40
54
|
async fill(selector, value) {
|
|
41
|
-
let element = await this._locate(selector);
|
|
55
|
+
let element = await this._locate(selector, this.page);
|
|
42
56
|
await element.fill(value);
|
|
43
57
|
await element.dispatchEvent("change");
|
|
44
58
|
}
|