Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying multiple conditions in xpath

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']");
like image 904
Zack Avatar asked Feb 15 '15 18:02

Zack


1 Answers

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

//*[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 xpaths

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')]
like image 164
Saifur Avatar answered Oct 27 '22 07:10

Saifur