schickling / chromeless

🖥 Chrome automation made simple. Runs locally or headless on AWS Lambda.
https://chromeless.netlify.com
MIT License
13.24k stars 575 forks source link

Xpath selector support #228

Open maruidea opened 7 years ago

maruidea commented 7 years ago

Is chromeless support xpath selector?

adieuadieu commented 7 years ago

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

maruidea commented 7 years ago

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.

sonnguyen1989 commented 7 years ago

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?

adieuadieu commented 7 years ago

@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.

sonnguyen1989 commented 7 years ago

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

mdeora commented 7 years ago

+1 for xpath support