CodeceptJS
CodeceptJS copied to clipboard
Playwright: WebKit: I.waitForText() with XPath element fails: TypeError: $XPath is not a function
What are you trying to achieve?
I.waitForText("Joe7520373868311179 Autotest010825480018201938", 20, locate(".right.menu").last().find(".dropdown"));
should pass
What do you get instead?
It fails:
Text "Joe7520373868311179 Autotest010825480018201938" was not found on page after 20 sec
page.waitForFunction: Evaluation failed: TypeError: $XPath is not a function. (In '$XPath(null, locator)', '$XPath' is "function $XPath(element, selector) {
const found = document.evaluate(selector, element || document.body, null, 5, null);
const res = [];
let current = null;
while (current = found.iterateNext()) {
res.push(current);
}
return res;
}")
Error: Text "Joe7520373868311179 Autotest010825480018201938" was not found on page after 20 sec
page.waitForFunction: Evaluation failed: TypeError: $XPath is not a function. (In '$XPath(null, locator)', '$XPath' is "function $XPath(element, selector) {
const found = document.evaluate(selector, element || document.body, null, 5, null);
Scenario Steps:
- I.waitForText("Joe7520373868311179 Autotest010825480018201938", 20, {xpath: (.//*[(contains(concat(' ', normalize-space(./@class), ' '), ' right ') and contains(concat(' ', normalize-space(./@class), ' '), ' menu '))])[position()=last()-0]//*[contains(concat(' ', normalize-space(./@class), ' '), ' dropdown ')]}) at Object.loginSuccess (/home/mirao/workspace/codeceptjs/tests/spork-publisher/pages/Login.js:135:11)
Note that only WebKit browser is affected. It works well in Chromium and Firefox Nightly.
Details
- CodeceptJS version: 3.0.6
- NodeJS Version: v12.22.1
- Operating System: Ubuntu 20.04/21.04
- Playwright 1.11.1
- WebKit 1472
Same for : "playwright": "1.13.1", "codeceptjs": "3.1.1" versions
I can see the same issue in method waitNumberOfVisibleElements
:
Code: I.waitNumberOfVisibleElements({xpath: .//*[contains(concat(' ', normalize-space(./@class), ' '), ' ReactVirtualized__Grid__innerScrollContainer ')]//div[@role = 'row']}, 2)
Result:
The number of elements ({xpath: .//*[contains(concat(' ', normalize-space(./@class), ' '), ' ReactVirtualized__Grid__innerScrollContainer ')]//div[@role = 'row']}) is not 2 after 60 sec
page.waitForFunction: TypeError: $XPath is not a function. (In '$XPath(null, locator)', '$XPath' is "function $XPath(element, selector) {
const found = document.evaluate(selector, element || document.body, null, 5, null);
const res = [];
let current = null;
while (current = found.iterateNext()) {
res.push(current);
}
return res;
}")
When I use seeNumberOfVisibleElements
instead of waitNumberOfVisibleElements
, it works fine.
Used SW:
- CodeceptJS 3.3.3
- Playwright 1.22.2, WebKit 15.4
I think its basically any method that uses xpath locators with a combination of wait?
I am seeing the same for I.waitForEnabled('xpath locator')
This happening only in webkit (safari)
page.waitForFunction: TypeError: $XPath is not a function. (In '$XPath(null, locator)', '$XPath' is "function $XPath(element, selector) {
const found = document.evaluate(selector, element || document.body, null, 5, null);
const res = [];
let current = null;
while (current = found.iterateNext()) {
res.push(current);
}
return res;
}")
Same problem for me too, Webkit
Closed for now! Feel free to reopen if you still encounter the issue with latest version and would be nice to provide a sample code to reproduce the issue.
Which version contains the fix? Would love to see the corresponding commit.
we moved to use Locator so I think that solved the issue -> https://github.com/codeceptjs/CodeceptJS/blob/3.x/lib/helper/Playwright.js#L2637
Still I can see the issue for I.waitForEnabled()
, with CodeceptJS 3.5.14, Playwright 1.42.1, WebKit
I wait for enabled {xpath: //button[contains(., 'Add Lesson')]}
› Unhandled Promise Rejection: TypeError: $XPath is not a function. (In '$XPath(null, locator)', '$XPath' is "function $XPath(element, selector) {
const found = document.evaluate(selector, element || document.body, null, 5, null)...
at unknown (undefined:3:22)
at predicate (:13:30)
at next (:32:40)
at unknown (:42:15)
at evaluate (:228:24)
at unknown (:1:52)
I.waitForElement()
works well.