xml - Using XPATH to search text containing -
i use xpather browser check xpath expressions on html page.
my end goal use these expressions in selenium testing of user interfaces.
i got html file content similar this:
<tr> <td>abc</td> <td> </td> </tr>
i want select node text containing string " ".
with normal string "abc" there no problem. use xpath similar //td[text()="abc"].
when try an xpath //td[text()=" "] returns nothing. there special rule concerning texts "&" ?
it seems openqa, guys behind selenium, have addressed problem. defined variables explicitely match whitespaces. in case, need use xpath similar //td[text()="${nbsp}"].
i reproduced here text openqa concerning issue (found here):
html automatically normalizes whitespace within elements, ignoring leading/trailing spaces , converting spaces, tabs , newlines single space. when selenium reads text out of page, attempts duplicate behavior, can ignore tabs , newlines in html , assertions based on how text looks in browser when rendered. replacing non-visible whitespace (including non-breaking space "
") single space. visible newlines (<br>,<p>, ,<pre>formatted new lines) should preserved.we use same normalization logic on text of html selenese test case tables. has number of advantages. first, don't need @ html source of page figure out assertions should be; "
" symbols invisible end user, , shouldn't have worry them when writing selenese tests. (you don't need put " " markers in test case asserttext on field contains " ".) may put newlines , spaces in selenese<td>tags; since use same normalization logic on test case on text, can ensure assertions , extracted text match exactly.this creates bit of problem on rare occasions when want/need insert whitespace in test case. example, may need type text in field this: "
foo". if write<td>foo </td>in selenese test case, we'll replace spaces 1 space.this problem has simple workaround. we've defined variable in selenese,
${space}, value single space. can use${space}insert space won't automatically trimmed, this:<td>foo${space}${space}${space}</td>. we've included variable${nbsp}, can use insert non-breaking space.note xpaths not normalize whitespace way do. if need write xpath
//div[text()="hello world"]html of link "hello world", you'll need insert real " " selenese test case match, this://div[text()="hello${nbsp}world"].
Comments
Post a Comment