Open maruidea opened 7 years ago
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
Is chromeless support xpath selector?