dalekjs / dalek

[unmaintained] DalekJS Base framework
MIT License
695 stars 63 forks source link

XPath support #3

Open davidjdixon opened 11 years ago

davidjdixon commented 11 years ago

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()).

asciidisco commented 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 :)

spacebeers commented 11 years ago

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.

davidjdixon commented 11 years ago

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.

victorhooi commented 10 years ago

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

http://stackoverflow.com/questions/21083952/xpath-expression-to-select-nodes-based-on-presence-of-child-node

asciidisco commented 10 years ago

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 :)

rothshahar commented 10 years ago

I'll try to take a stab at this.

asciidisco commented 10 years ago

:+1:

asm0dey commented 9 years ago

:+1: It's only possible with xpath to have selector like //...../td[contains(.,'text')] if I understand correctly

davidlinse commented 9 years ago

Any news on this ?

Harryson commented 9 years ago

:+1: