automation_model 1.0.58 → 1.0.60

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.
@@ -43,60 +43,66 @@ class StableBrowser {
43
43
  }
44
44
  throw new Error("unknown locator type");
45
45
  }
46
- async _locateElementByText(scope, text1, regex = false, _params = null) {
46
+ async _locateElementByText(scope, text1, tag1, regex = false, _params = null) {
47
47
  //const stringifyText = JSON.stringify(text);
48
- return await scope.evaluate((text) => {
49
- function isParent(parent, child) {
50
- let currentNode = child.parentNode;
51
- while (currentNode !== null) {
52
- if (currentNode === parent) {
53
- return true;
48
+ return await scope.evaluate(
49
+ ([text, tag]) => {
50
+ function isParent(parent, child) {
51
+ let currentNode = child.parentNode;
52
+ while (currentNode !== null) {
53
+ if (currentNode === parent) {
54
+ return true;
55
+ }
56
+ currentNode = currentNode.parentNode;
54
57
  }
55
- currentNode = currentNode.parentNode;
58
+ return false;
56
59
  }
57
- return false;
58
- }
59
- let elements = Array.from(document.querySelectorAll("*"));
60
- let randomToken = null;
60
+ if (!tag) {
61
+ tag = "*";
62
+ }
63
+ let elements = Array.from(document.querySelectorAll(tag));
64
+ let randomToken = null;
61
65
 
62
- text = text.trim();
63
- const foundElements = [];
64
- for (let i = 0; i < elements.length; i++) {
65
- const element = elements[i];
66
- if (element.innerText && element.innerText.trim() === text) {
67
- foundElements.push(element);
66
+ text = text.trim();
67
+ const foundElements = [];
68
+ for (let i = 0; i < elements.length; i++) {
69
+ const element = elements[i];
70
+ if (element.innerText && element.innerText.trim() === text) {
71
+ foundElements.push(element);
72
+ }
68
73
  }
69
- }
70
- let noChildElements = [];
71
- for (let i = 0; i < foundElements.length; i++) {
72
- let element = foundElements[i];
73
- let hasChild = false;
74
- for (let j = 0; j < foundElements.length; j++) {
75
- if (i === j) {
76
- continue;
74
+ let noChildElements = [];
75
+ for (let i = 0; i < foundElements.length; i++) {
76
+ let element = foundElements[i];
77
+ let hasChild = false;
78
+ for (let j = 0; j < foundElements.length; j++) {
79
+ if (i === j) {
80
+ continue;
81
+ }
82
+ if (isParent(element, foundElements[j])) {
83
+ hasChild = true;
84
+ break;
85
+ }
77
86
  }
78
- if (isParent(element, foundElements[j])) {
79
- hasChild = true;
80
- break;
87
+ if (!hasChild) {
88
+ noChildElements.push(element);
81
89
  }
82
90
  }
83
- if (!hasChild) {
84
- noChildElements.push(element);
85
- }
86
- }
87
- let elementCount = 0;
88
- if (noChildElements.length > 0) {
89
- for (let i = 0; i < noChildElements.length; i++) {
90
- if (randomToken === null) {
91
- randomToken = Math.random().toString(36).substring(7);
91
+ let elementCount = 0;
92
+ if (noChildElements.length > 0) {
93
+ for (let i = 0; i < noChildElements.length; i++) {
94
+ if (randomToken === null) {
95
+ randomToken = Math.random().toString(36).substring(7);
96
+ }
97
+ let element = noChildElements[i];
98
+ element.setAttribute("data-blinq-id", "blinq-id-" + randomToken);
99
+ elementCount++;
92
100
  }
93
- let element = noChildElements[i];
94
- element.setAttribute("data-blinq-id", "blinq-id-" + randomToken);
95
- elementCount++;
96
101
  }
97
- }
98
- return { elementCount: elementCount, randomToken: randomToken };
99
- }, text1);
102
+ return { elementCount: elementCount, randomToken: randomToken };
103
+ },
104
+ [text1, tag1]
105
+ );
100
106
  }
101
107
 
102
108
  async _collectLocatorInformation(selectorHierarchy, index = 0, scope, foundLocators, _params) {
@@ -110,7 +116,7 @@ class StableBrowser {
110
116
  let locatorSearch = selectorHierarchy[index];
111
117
  let locator = null;
112
118
  if (locatorSearch.text) {
113
- let result = await this._locateElementByText(scope, locatorSearch.text, false, _params);
119
+ let result = await this._locateElementByText(scope, locatorSearch.text, locatorSearch.tag, false, _params);
114
120
  if (result.elementCount === 0) {
115
121
  return;
116
122
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "automation_model",
3
- "version": "1.0.58",
3
+ "version": "1.0.60",
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",