Selenium et xpath: trouver une div avec une classe / id et vérifier le texte à l'intérieur

J'essaie d'avoir xpath trouver un div et vérifiez que le div a un string de texte à l'intérieur.

Voici la HTML:

<div class="Caption">
  Model saved
</div>

et

<div id="alertLabel" class="gwt-HTML sfnStandardLeftMargin sfnStandardRightMargin sfnStandardTopMargin">
  Save to server successful
</div>

C'est le code que j'utilise pour le moment:

viewerHelper_.getWebDriver().findElement(By.xpath("//div[contains(@class, 'Caption' and .//text()='Model saved']"));
viewerHelper_.getWebDriver().findElement(By.xpath("//div[@id='alertLabel'] and .//text()='Save to server successful']"));

Spécifiquement:

//div[contains(@class, 'Caption' and .//text()='Model saved']
//div[@id='alertLabel'] and .//text()='Save to server successful']

source d'informationauteur Chris Byatt