2015-07-10 56 views
0

我想要找到一个xpath来定位文本中的文本,该文本中说的text to locate in the second portion of the xpath通过首先在div中的表中的td中查找tr中的图像在它下面。Xpath - 需要一个xpath来定位兄弟表中的元素

这是HTML结构(简体/伪代码):

<table> 
    <tbody> 
    <tr> 
    <td> 
    <span>id to locate in the second portion of the xpath 
    </span> 
    </td> 
    </tr> 
    </tbody> 
</table> 
<div> 
    <table> 
     <tbody> 
     <tr> 
     <td> 
     <img>imgPartStatus</img> 
     </td> 
     </tr> 
     </tbody> 
     </table> 

这是我的尝试:

//tr[starts-with(td/img[contains(@id,'imgPartStatus')])]preceding::(table/tbody/tr/td/span[contains(@id,'idto locate in the second portion of the xpath')]) 
//tr[starts-with(td/img[contains(@id,'imgPartStatus')])]sibling::(table/tbody/tr/td/span[contains(@id,'idto locate in the second portion of the xpath')]) 

所以第一部分//tr[starts-with(td/img[contains(@id,'imgPartStatus')])]已经被覆盖,并且工作正常。但我需要走出img,td,tr,表格,脱离div,并查看上面的表格。说得通?感谢您检查我的问题。

此外,不知道标题的“兄弟表”。它可能不会被这样调用。抱歉!

+0

我没有看到第二个参数在'// TR [开始,用(TD/IMG你'开始,with'通话[含有(@ ID, 'imgPartStatus')])]'。我没有在HTML或XML输入中看到任何'id'属性。 –

+0

我没有包含它以使其功能,而是为了给出结构的概念。它确实需要成为确切的代码吗? – zuri

回答

1

它花了一点时间,但在这里它是:

//div[starts-with(table/tbody/tr/td/img[contains(@id,'imgPartStatus')]/preceding::table[1]/tbody/tr/td/span[contains(@id,'idto locate in the second portion of the xpath')]