java 在 xpath 中指定多个条件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28529577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Specifying multiple conditions in xpath
提问by Zack
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.
我想选择所有带有<td class='blob-code blob-code-addition'> and <td class='blob-code blob-code-deletion'>
. 所以我试图or
在这两个谓词之间包含条件。这是行不通的。但是,如果我只包含两个类中的一个,它就可以工作。这里有什么问题?语法有问题。
By getChanges = By.xpath("//td[@class='blob-code blob-code-addition'] or //td[@class='blob-code blob-code-deletion']");
回答by Saifur
You want to specify that like the following:
你想像下面这样指定:
//td[contains(@class,'deletion') or contains(@class,'addition')]
or
或者
//td[contains(@class,'blob-code blob-code-addition') or contains(@class,'blob-code blob-code-deletion')]
If you want to do a tag
independent search then you can simply use
如果你想做一个tag
独立的搜索,那么你可以简单地使用
//*[contains(@class,'blob-code blob-code-addition') or contains(@class,'blob-code blob-code-deletion')]
From your answer it looks like you are trying to concatenate two different xpath
s
从您的回答看来,您正在尝试连接两个不同的xpath
s
However, contians()
is not mandatory here. You also can do without this
但是,contians()
这里不是强制性的。你也可以没有这个
//*[(@class='blob-code blob-code-addition') or (@class='blob-code blob-code-deletion')]
回答by Anil Jain
using pom:
@FindBy(xpath ="//span[contains(@class,'vui-menuitem-label-text') and normalize-space(.) = 'Clone']")
使用 pom:
@FindBy(xpath ="//span[contains(@class,'vui-menuitem-label-text') and normalize-space(.) = 'Clone']")
回答by Mike ASP
what works for me is below expression using "|" characterinside my expression-
对我有用的是下面使用“|”的表达式 我的表情里面的性格-
By element = driver.findElement(By.xpath("//button[@clas='xyz'] | //button[@clas='abc']"))
By element = driver.findElement(By.xpath("//button[@clas='xyz'] | //button[@clas='abc']"))
I used above expression for JAVA + Selenium + Maven project
我将上述表达式用于 JAVA + Selenium + Maven 项目