Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mirao opened this issue Jun 5, 2021 · 9 comments

Comments

@mirao
Copy link
Contributor

mirao commented Jun 5, 2021

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
@hatufacci
Copy link
Contributor

hatufacci commented Aug 19, 2021

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

@mirao
Copy link
Contributor Author

mirao commented Jun 25, 2022

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

@ktryniszewski-mdsol
Copy link
Contributor

ktryniszewski-mdsol commented Aug 21, 2022

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

@ua1wcz
Copy link

ua1wcz commented Mar 2, 2023

Same problem for me too, Webkit

@kobenguyent
Copy link
Collaborator

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.

@fwouts
Copy link
Contributor

fwouts commented Dec 13, 2023

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

@kobenguyent
Copy link
Collaborator

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

@mirao
Copy link
Contributor Author

mirao commented Apr 1, 2024

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.

@oschlegel
Copy link

i can reproduce the same issue. did a workaround by replacing my locate usages with css selectors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants