sinco icon indicating copy to clipboard operation
sinco copied to clipboard

Support for Xpath selectors alongside CSS ones

Open SnoCold opened this issue 4 years ago • 5 comments

Summary

What:

A feature to enable methods to be able to work with XPATH selectors as well.

Why:

XPATH used to be an industry standard before CSS selectors started becoming popular. However there is still a good number of people who are accustomed to the old ways. (Me Included)

Acceptance Criteria

Below is a list of tasks that must be completed before this issue can be closed.

  • [ ] Write documentation
  • [ ] Write unit tests
  • [ ] Write integration tests

Example Pseudo Code (for implementation)

await Sinco.click('xpath=//label[text()="Yes"]/ancestor::div/descendant::input[@type="radio"]'); //Just an example xpath.

SnoCold avatar Oct 25 '21 05:10 SnoCold

@SnoCold it seems if i try use $x via the protocol, it comes up as $x is not defined, i wonder if you have an idea how to enable this? or if it can be anabled at all, maybe it isn't supported in the protocol and puppeteer have a polyfill?

ebebbington avatar Dec 05 '21 15:12 ebebbington

@ebebbington I actually had the same idea, but now that you mentioned it, looks like I will have to look for something else.. currently away but will try to find the feasibility asap...

SnoCold avatar Dec 05 '21 15:12 SnoCold

OO ok so i found this by chance, adding includeCommandLineAPI to Runtime.evaluate opens up $x, which is good news, so just need ot figure out how we enable it when evaluatePage is passed a function (because when its a function, the internal code uses different logic to evaluate)

ebebbington avatar Dec 05 '21 15:12 ebebbington

it could be possible with passing in a function if we change our code to:

if (pageCommand is a function) {
  pageCommand = `const __one__ = ${pageCommand}; __one__()`
  this.evaluayePage(pageCommand)
}

and you could use it like so:

evaluatePage(() => {
  return $x('//div')
})

ebebbington avatar Dec 05 '21 15:12 ebebbington

will be partially done in #91 by allowing .evaluatePage('$x('//div'))`

ebebbington avatar Dec 05 '21 22:12 ebebbington