flagpole icon indicating copy to clipboard operation
flagpole copied to clipboard

The string 'following-sibling:://*' is not a valid XPath expression

Open johnsickels opened this issue 5 years ago • 5 comments
trafficstars

Using .getNextSibling() errors in browser scenarios:

 ✕  Error: Evaluation failed: DOMException: Failed to execute 'evaluate' on 'Document': The string 'following-sibling:://*' is not a valid XPath expression. at __puppeteer_evaluation_script__:3:37

But succeeds in other scenarios (html):

 ✔  span.current-school under Next Sibling of h1 [0] has text "Gulf HS"

Flagpole version: 2.5.3

Reproduction:

import flagpole from "flagpole";

const suite = flagpole("Basic Smoke Test of Site");

suite
  .scenario("Homepage Loads", "browser")
  .open("https://fl.milesplit.com/athletes/pro/1038826/stats")
  .next(async (context) => {
    const h1 = await context.exists("h1");
    const p = await h1.getNextSibling();
    const currentSchool = await p.find("span.current-school");
    await context.assert(currentSchool).hasText("Gulf HS");
  });

johnsickels avatar Sep 08 '20 16:09 johnsickels

I think it has to do with this

johnsickels avatar Sep 08 '20 17:09 johnsickels

Also finding issue here

const streamIDLabel = await context.find(".prop", "streamId");
const streamIDAncestor = await streamIDLabel.getAncestor("a");

fails on error

Error: Evaluation failed: DOMException: Failed to execute 'evaluate' on 'Document': The string 'ancestor:://a' is not a valid XPath expression. at __puppeteer_evaluation_script__:3:39

johnsickels avatar Oct 15 '20 15:10 johnsickels

Started working on this but this is gonna take me longer because xpath is kind of a pain. Gonna release the update without this fix and then try to circle back

jasonbyrne avatar Oct 21 '20 21:10 jasonbyrne

In https://github.com/flagpolejs/flagpole/blob/1cb99e60c9650f07e855c386f8a9c0b470a3da87/src/puppeteer/browserelement.ts#L562-L569

return this.$.$x(`//${prefix}${cssXPath(selector).slice(2)}${suffix}`);

This is all the work I've done so far. This is working for .getAncestor("a") and .getNextSibling(".num"), but NOT for .getFirstChild()

For the last, I still get

child::undefined[1]

I closed the PR stale because I wanted the branch name back

johnsickels avatar Jun 09 '21 19:06 johnsickels

Getting error

✕  TypeError: csstoxpath_1.default is not a function

when using

    const listItems = await context.findAll(".upcoming .events-group li");
    const firstItem = listItems[0];
    context.assert("Found first li", firstItem).exists();
    const secondItem = await firstItem.getNextSibling();

johnsickels avatar Sep 29 '21 15:09 johnsickels