Java – 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']");

Best Solution

You want to specify that like the following:

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


//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')]