我正在尝试让 xpath
找到一个 div
并验证 div
是否具有特定的 string
里面的文字。
这是 HTML
:
<div class="Caption">
Model saved
</div>
和
<div id="alertLabel" class="gwt-HTML sfnStandardLeftMargin sfnStandardRightMargin sfnStandardTopMargin">
Save to server successful
</div>
这是我目前使用的代码:
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']"));
具体来说:
//div[contains(@class, 'Caption' and .//text()='Model saved']
//div[@id='alertLabel'] and .//text()='Save to server successful']
最佳答案
验证这一点:-
<div class="Caption">
Model saved
</div>
写这个-
//div[contains(@class, 'Caption') and text()='Model saved']
并验证这一点:-
<div id="alertLabel" class="gwt-HTML sfnStandardLeftMargin sfnStandardRightMargin sfnStandardTopMargin">
Save to server successful
</div>
写这个-
//div[@id='alertLabel' and text()='Save to server successful']
关于java - Selenium 和 xpath : finding a div with a class/id and verifying text inside,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18570622/