Open davidjdixon opened 11 years ago
I initially thought that the typical frontend dev doesn't like to write XPath, but after receiving a few requests, I believe, adding XPath can help a lot of people.
I`thinking that the following syntax could be used to add it (comments/thoughts welcome):
test.open('http://dalekjs.com')
.click(test.xpath('/html/body/div/div/div[5]/div[2]/a'))
.assert.url('https://twitter.com/dalekjs')
.done();
When I started dalek I thought about adding jQuery-style selector extensions to it, but then I realized that this is an extremely complex thing to do. Which means, yes I hope they will be available in the future, but when this will be, I don't know yet :(
Thank you for testing dalek & adding your thoughts :)
I've been writing tests using x-paths and finding them very very fragile. The smallest change in the mark up can cause your test to fail and big changes can mean the whole test being written again. Annoyingly they are useful but I'm considering adding testing hooks into the mark up and using a Grunt task to remove them before a release.
I'd be interested in x-paths in Dalek though.
XPaths can be fragile if, like in CSS you are overly specific. eg /div/div/a is highly specific, whereas //a is much more general. Similarly, //a[@class="foo"] is very specific, and will fail if you have multiple classes. Instead you would likely want //a[contains(concat(' ',normalize-space(@class),' '),' foo ')]... although in this case, a css selector would be a better bet.
I'd like to have XPath support in DalekJS.
I'm currently using XPath with Selenium/Splinter - yes, they can be fragile, if you make them depend on hierarchy - but then so can
And in fact, there's XPath queries in our current test suite for which I'm not aware of CSS equivalents - e.g.:
I personally had never an issue with CSS selectors, especially when supporting modern browsers you have a set that is easily understandable & quite powerful. See http://www.w3.org/TR/css3-selectors/#selectors
But, as stated above, I see the need for this, but other things have a higher priority. Pull requests are always welcome, if any problems exist, I'm happy to assist in solving :)
I'll try to take a stab at this.
:+1:
:+1: It's only possible with xpath to have selector like //...../td[contains(.,'text')] if I understand correctly
Any news on this ?
:+1:
I would like to see XPath support to target elements that would be normally awkward (or sometime unfeasible) to target using standard CSS selectors.
Another possibility is to support JQuery-style selector extension such as which can then be used to offer a similar feature set to what XPath could offer (eg :contains()).