seminolas
seminolas

Reputation: 31

xpath text() comparison

(new to web development) Hi, can anyone explain me why this

Object x=getCurrentPage().getByXPath("//div[@class = 'notification']
                                       /text() =
                                      'Product saved successfully'").get(0);

returns a Boolean false object, but this

Object y = getCurrentPage().getByXPath("//div[@class='notification']
                                         /text()").get(0);

returns DomText object with data Product saved successfully?

why is the boolean false? it seems to me it should return true.

p.s. when i try the same query in XPathBrowser (FF plugin) it returns boolean:true

thanks a lot

Upvotes: 2

Views: 9585

Answers (2)

javamonkey79
javamonkey79

Reputation: 17775

Your first xpath is doing a boolean operation while the second is asking for text from the DOM.

EDIT: This is a response to the initial question (see revisions), not the question at present (which has changed).

Upvotes: 1

Wrikken
Wrikken

Reputation: 70520

Use:

//div[@class='notification']/text()[ . = 'Product saved successfully']

Because the collection //div[@class='notification']/text() will never equal the string 'Product saved successfully'.

As Alejandro & LarsH pointed out (and they're both right), this answer was utterly wrong. The point is not that //div[@class = 'notification']/text() = 'Product saved successfully' doesn't work, it's just that the .get(0) doesn't make sense on the boolean the first option returns (it simply states true, as in 'that node exists')

Upvotes: 4

Related Questions