java - Extract Text from BR tags -



java - Extract Text from BR tags -

i have been able extract text using selenium before, i'am having problem extracting numbers between < br > tags. here sample of html code.

<div class="pagebodydiv"> <table class="datadisplaytable" summary="this table display needed information." width="100%"> <tr> <td class="nttitle" scope="colgroup" >working title</a></td> </tr> <tr> <td class="ntdefault"> farther info on subject <br> 3.000 <br> 2.000 <br> <br> <br> <br> <br> more info <br> <br> </table>

so far have tried using:

webelement creditinfo = driver.findelement(by.xpath("//div[@class='pagebodydiv']/text()[preceding-sibling::br]

and elements numinfo = doc.select("br");

however, maintain running nosuchelementexception error, invalidselectorexception error, or doesn't homecoming anything. ideas on how can information?

you can select text nodes between <br> tags. in html (not xhtml) deed self-closing tags (like <br/>). based on behaviour, select text nodes have <br> tag before , after using:

//table[@class='datadisplaytable']/tr/td[@class="ntdefault"] /text()[preceding-sibling::node()[1][self::br] , following-sibling::node()[1][self::br]]

that select blank lines , character text not number.

you can rid of empty space nodes adding [normalize-space(.) != ''] end of look (which homecoming 3 nodes). , can select which node want using positional predicate @ end of look ([1] select first node.

the look below selects text node containing value 2.000:

//table[@class='datadisplaytable']/tr/td[@class="ntdefault"] /text()[preceding-sibling::node()[1][self::br] , following-sibling::node()[1][self::br]][normalize-space(.) != ''][2]

note: i'm assuming source has tag names in uppercase, since in xpath <td> not same <td>. i'm not sure how tolerant selenium when parsing html.

java selenium xpath

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -