在 xpath 中指定多个条件 [英] Specifying multiple conditions in xpath

查看:183
本文介绍了在 xpath 中指定多个条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想选择带有 的所有标签和 .所以我试图在这两个谓词之间包含 or 条件.这是行不通的.但是,如果我只包含两个类中的一个,它就可以工作.这里有什么问题?语法有问题.

I want to select all the tags with <td class='blob-code blob-code-addition'> and <td class='blob-code blob-code-deletion'> . So I am trying to include or condition here between the two predicates. It does not work. However, if I include only one of the two classes it works . What is the problem here? Something is wrong with the syntax.

By getChanges = By.xpath("//td[@class='blob-code blob-code-addition'] or  //td[@class='blob-code blob-code-deletion']");

推荐答案

你想像下面这样指定:

//td[contains(@class,'deletion') or contains(@class,'addition')]

//td[contains(@class,'blob-code blob-code-addition') or contains(@class,'blob-code blob-code-deletion')]

如果你想做一个tag独立搜索,那么你可以简单地使用

If you want to do a tag independent search then you can simply use

//*[contains(@class,'blob-code blob-code-addition') or contains(@class,'blob-code blob-code-deletion')]

从您的回答看来您正在尝试连接两个不同的 xpaths

From your answer it looks like you are trying to concatenate two different xpaths

然而,contians() 在这里不是强制性的.你也可以不用这个

However, contians() is not mandatory here. You also can do without this

//*[(@class='blob-code blob-code-addition') or (@class='blob-code blob-code-deletion')]

这篇关于在 xpath 中指定多个条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆