在表中,行具有以下层次结构:
//div[@class='table']
//div[@class='some_row_n']//......some xpath...//<child with text abc>
//div[@class='some_row_m']//......some xpath...//<child with text xyz>
我可以通过
//div[@class='table']//div[descendant::text()="abc"]
但是有没有一种方法可以让我找出父行的xpath 'some_row_n'(或'some_row_m'取决于搜索的文本)。问题是上面 xpath 部分中的项目数量.....some xpath...在设计时是未知的。
我试图实现这一点,而不必遍历每一行来查找文本。这可以极大地减少编码工作。