Skip to content

Commit 85fa81a

Browse files
committed
fixup js changes
1 parent b0562c3 commit 85fa81a

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

tests/pages/pages.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -318,32 +318,30 @@ def scrollToRevealElement(self, selector=None, xpath=None, stuckToBottom=True):
318318
var moduleVar = arguments[2];
319319
var modulePath = arguments[3];
320320
321-
async function run() {
321+
(async function() {
322322
try {
323323
if (!window.__stickyNavModule) {
324324
window.__stickyNavModule = await import(modulePath);
325325
}
326326
327-
const handler = window.__stickyNavModule[moduleVar];
328-
let element;
327+
// Re-find the element inside the promise execution
328+
// so it is as fresh as possible
329+
const element = (type === 'selector')
330+
? document.querySelector(locator)
331+
: document.evaluate(locator, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
329332
330-
if (type === 'selector') {
331-
element = document.querySelector(locator);
332-
} else {
333-
element = document.evaluate(locator, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
334-
}
333+
const handler = window.__stickyNavModule[moduleVar];
335334
336335
if (element && handler) {
337336
handler.scrollToRevealElement(element);
338337
callback(true);
339338
} else {
340-
callback(false);
339+
callback('Element not found or handler missing');
341340
}
342341
} catch (e) {
343342
callback('Error: ' + e.message);
344343
}
345-
}
346-
run();
344+
})();
347345
"""
348346

349347
# Pass the variables separately. Selenium serializes them correctly.

0 commit comments

Comments
 (0)