automation_model 1.0.4 → 1.0.6

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.
@@ -9,36 +9,50 @@ class StableBrowser {
9
9
  timeout: 60000,
10
10
  });
11
11
  }
12
- async _locate(selector) {
13
- if (typeof selector === "object") {
14
- try {
12
+ async _locate(selector, scope) {
13
+ try {
14
+ if (Array.isArray(selector)) {
15
+ let currentScope = scope;
16
+
17
+ for (let i = 0; i < selector.length; i++) {
18
+ currentScope = (
19
+ await this._locate(selector[i], currentScope)
20
+ ).first();
21
+ }
22
+ return currentScope;
23
+ }
24
+ if (typeof selector === "object") {
15
25
  if (selector.css) {
16
- return await this.page.locator(selector.css);
26
+ return (await scope.locator(selector.css)).first();
17
27
  }
18
28
  if (selector.role) {
19
- return await this.page.getByRole(selector.role[0], selector.role[1]);
29
+ return (
30
+ await scope.getByRole(selector.role[0], selector.role[1])
31
+ ).first();
20
32
  }
21
33
  if (selector.text) {
22
- return await this.page.getByText(selector.text);
34
+ return await scope.getByText(selector.text);
23
35
  }
24
- throw new Error(`Unknown locator type ${type}`);
25
- } catch (e) {
26
- console.log("invalid locator object, will try to parse as text");
27
36
  }
37
+ throw new Error(`Unknown locator type ${type}`);
38
+ } catch (e) {
39
+ console.log("invalid locator object, will try to parse as text");
28
40
  }
29
41
 
30
42
  if (selector.startsWith("TEXT=")) {
31
- return await this.page.getByText(selector.substring("TEXT=".length));
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "automation_model",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "An automation infrastructure module to be use for generative AI automation projects.",
5
5
  "main": "bin/index.js",
6
6
  "type": "module",