xml - XPath for text between tags -


i want verify xpath canoo webtest.

my html looks this:

<div id="mydivid">firstname lastname</div> 

the space between firstname , lastname created "&nbsp;".

i tried following fails when test firepath or console of firebug.

//div[@id='mydivid' , contains(.,'firstname lastname')] //div[@id='mydivid' , contains(.,'firstname&nbsp;lastname')] //div[@id='mydivid'][contains(text(),'firstname lastname')] //div[@id='mydivid'][matches(text(),'firstname.lastname')] 

sometimes don't know difference between versions. more or less try , error after found 1000 solutions on stackoverflow. never works me :/ tried understand difference of . , text() , how contains , matches works. cant figure out long test cases fail.

what did wrong?

seems problem is, nbsp entity not defined <!entity nbsp "&#160;">
can try (should work):

"//div[@id='mydivid' , contains(text(),'firstname&#160;lastname')])" 

or

"//div[@id='mydivid' ,  text() ='firstname&#160;lastname'])" 

text() returns text of current element.
. (in string context) returns test of child of current element.

in example there no different because div not have child beside of text.

update: seems special issue of firefox extension firepath. firebug document.evalute do:

var xpath = "//div[@id='mydivid' , text() ='firstname\xa0lastname']"; divs = document.evaluate(xpath, document, null, xpathresult.any_type, null);  d1=divs.iteratenext(); 

but consider javascript encoding of nbsp \0xa0.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -