@@ -37,33 +37,31 @@ def body
37
37
end
38
38
39
39
def wait_for_selector ( css : nil , xpath : nil , timeout : 5000 , interval : 100 )
40
- tap do
41
- evaluate_func ( %(
42
- function(selector, isXpath, timeout, interval) {
43
- var attempts = 0;
44
- var max = timeout / interval;
45
- function waitForSelector(resolve, reject) {
46
- if (attempts > ((max < 1) ? 1 : max)) {
47
- return reject(new Error("Not found element match the selector: " + selector));
48
- }
49
- var element = isXpath
50
- ? document.
51
- evaluate(selector, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
52
- : document.querySelector(selector);
53
- if (element !== null) {
54
- return resolve(element);
55
- }
56
- setTimeout(function () {
57
- waitForSelector(resolve, reject);
58
- }, interval);
59
- attempts++;
40
+ evaluate_func ( %(
41
+ function(selector, isXpath, timeout, interval) {
42
+ var attempts = 0;
43
+ var max = timeout / interval;
44
+ function waitForSelector(resolve, reject) {
45
+ if (attempts > ((max < 1) ? 1 : max)) {
46
+ return reject(new Error("Not found element match the selector: " + selector));
60
47
}
61
- return new Promise(function (resolve, reject) {
48
+ var element = isXpath
49
+ ? document.
50
+ evaluate(selector, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
51
+ : document.querySelector(selector);
52
+ if (element !== null) {
53
+ return resolve(element);
54
+ }
55
+ setTimeout(function () {
62
56
waitForSelector(resolve, reject);
63
- });
57
+ }, interval);
58
+ attempts++;
64
59
}
65
- ) , css || xpath , css . nil? && !xpath . nil? , timeout , interval , awaitPromise : true )
66
- end
60
+ return new Promise(function (resolve, reject) {
61
+ waitForSelector(resolve, reject);
62
+ });
63
+ }
64
+ ) , css || xpath , css . nil? && !xpath . nil? , timeout , interval , awaitPromise : true )
67
65
end
68
66
69
67
def xpath ( selector , within : nil )
0 commit comments