简体   繁体   English

xpath表达式,用于从具有子div的链接中选择文本

[英]xpath expression to select text from link with sub divs

I have a TA case where i find an element by xpath (really long one) 我有一个TA案例,其中我通过xpath找到了一个元素(真的很长)

$x("//tr[./td[contains(@class, 'description_short') and .//a[contains(@class, 'descShort') and normalize-space(text()) = normalize-space('xxxxxxxxx')]]]/.//img[starts-with(@id, 'tocart_')]")$x("//tr[./td[contains(@class, 'description_short') and .//a[contains(@class, 'descShort')]]]/.//img[starts-with(@id, 'tocart_')]")

It no longer works because somone came with the briliant idea to highlight the words in the link name so text() returns null. 它不再起作用,因为somone带有使链接名称中的单词突出显示的聪明点子,因此text()返回null。

The new text is : 新文本是:

<a href="#" class="x-dig-articleDetailSpx descShort"><b class="x-dig-articleDetailSpx descShort"><b class="x-dig-articleDetailSpx descShort">MDI,</b></b> P<b class="x-dig-articleDetailSpx descShort"><b class="x-dig-articleDetailSpx descShort">MDI,</b></b> <b class="x-dig-articleDetailSpx descShort">Isocyanat,MDF,</b> <b class="x-dig-articleDetailSpx descShort">Huntsman</b></a>

The old was: 旧的是:

<a href="#" class="x-dig-articleDetailSpx descShort"><b class="x-dig-articleDetailSpx descShort">xxxxxx</a>

I have no idea how to get the text from that new mess... anyone an idea? 我不知道如何从新的混乱中获取文本...有人知道吗?

Found it. 找到了。 you can use the string() function instead of text() 您可以使用string()函数代替text()

Kinda simple. 有点简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM