Chromeless: Xpath selector support

Created on 13 Aug 2017  Â·  6Comments  Â·  Source: prisma-archive/chromeless

Is chromeless support xpath selector?

API feature help wanted

Most helpful comment

I use xpath to select element based on its text e.g. "//button[. = 'Login']"
It's more resistant to dom changes and make code easier to read.

And on some web 2.0 websites, sometimes the element id always changes/generated every reload (e.g. on emberjs website I guess). and selecting based on its class name is too broad.

For example: https://seller.shopee.co.id/
Clicking Login button using xpath: "//button[. = 'Login']" is much more easier rather than using CSS selector and more resistant to dom changes.

Right now I use casperjs that support both CSS selector and Xpath selector, but I am thinking to switch to headless chrome.

All 6 comments

Hi @maruidea — Not at the moment. What's your use-case for xpath selectors?

I use xpath to select element based on its text e.g. "//button[. = 'Login']"
It's more resistant to dom changes and make code easier to read.

And on some web 2.0 websites, sometimes the element id always changes/generated every reload (e.g. on emberjs website I guess). and selecting based on its class name is too broad.

For example: https://seller.shopee.co.id/
Clicking Login button using xpath: "//button[. = 'Login']" is much more easier rather than using CSS selector and more resistant to dom changes.

Right now I use casperjs that support both CSS selector and Xpath selector, but I am thinking to switch to headless chrome.

Hi @adieuadieu
if we have a lot of button with type "submit" on one page. How to write click('button[type="submit"]') if not use xpath?

@sonnguyen1989 — If you know the index offset of the element you're targeting, you could select it with the CSS :nth-child(number) selector, e.g. select the 3rd submit button: click('button[type="submit"]:nth-child(3)')

We're not against supporting XPath and welcome any PRs which help implement the feature.

Thanks @adieuadieu,
Can we check button contains the string, then click it? It seems like click("button:contains('Send Message')") does not work.

+1 for xpath support

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adieuadieu picture adieuadieu  Â·  3Comments

just-boris picture just-boris  Â·  5Comments

ovheurdrive picture ovheurdrive  Â·  5Comments

eitansela picture eitansela  Â·  4Comments

queicherius picture queicherius  Â·  3Comments