CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

Playwright: WebKit: I.waitForText() with XPath element fails: TypeError: $XPath is not a function

Open mirao opened this issue 3 years ago • 3 comments

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

mirao avatar Jun 05 '21 19:06 mirao

Same for : "playwright": "1.13.1", "codeceptjs": "3.1.1" versions

hatufacci avatar Aug 19 '21 10:08 hatufacci

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

mirao avatar Jun 25 '22 09:06 mirao

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;
}")

ktryniszewski-mdsol avatar Aug 21 '22 04:08 ktryniszewski-mdsol

Same problem for me too, Webkit

ua1wcz avatar Mar 02 '23 07:03 ua1wcz

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.

kobenguyent avatar Oct 23 '23 12:10 kobenguyent

Which version contains the fix? Would love to see the corresponding commit.

fwouts avatar Dec 13 '23 00:12 fwouts

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

kobenguyent avatar Dec 13 '23 08:12 kobenguyent

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.

mirao avatar Apr 01 '24 08:04 mirao