Skip to main content

You can use try cache block.

String text = null;
try{
   text = driver.findElement(By.xpath(xpath1)).getText();
}catch(NoSuchElementException ex){
   text = driver.findElement(By.xpath(xpath2)).getText();
}

Hope that helps. P.S: This is just a pseudo code.

Mayur
  • 144
  • 7