Selenium 和 xpath:找到一个带有 class/id 的 div 并验证里面的文本 [英] Selenium and xpath: finding a div with a class/id and verifying text inside
本文介绍了Selenium 和 xpath:找到一个带有 class/id 的 div 并验证里面的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试让 xpath
找到一个 div
并验证 div
是否具有特定的 string
里面的文字.
这是HTML
:
模型已保存
和
保存到服务器成功
这是我目前使用的代码:
viewerHelper_.getWebDriver().findElement(By.xpath("//div[contains(@class, 'Caption' and .//text()='Model saved']"));viewerHelper_.getWebDriver().findElement(By.xpath("//div[@id='alertLabel'] and .//text()='保存到服务器成功']"));
特别是:
//div[contains(@class, 'Caption' and .//text()='Model saved']//div[@id='alertLabel'] 和 .//text()='保存到服务器成功']
解决方案
验证:-
模型已保存
写这个 -
//div[contains(@class, 'Caption') and text()='保存的模型']
并验证这一点:-
保存到服务器成功
写这个 -
//div[@id='alertLabel' and text()='保存到服务器成功']
I'm trying to have xpath
find a div
and verify that the div
has a specific string
of text inside.
Here's the HTML
:
<div class="Caption">
Model saved
</div>
and
<div id="alertLabel" class="gwt-HTML sfnStandardLeftMargin sfnStandardRightMargin sfnStandardTopMargin">
Save to server successful
</div>
This is the code I'm using at the 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']"));
Specifically:
//div[contains(@class, 'Caption' and .//text()='Model saved']
//div[@id='alertLabel'] and .//text()='Save to server successful']
解决方案
To verify this:-
<div class="Caption">
Model saved
</div>
Write this -
//div[contains(@class, 'Caption') and text()='Model saved']
And to verify this:-
<div id="alertLabel" class="gwt-HTML sfnStandardLeftMargin sfnStandardRightMargin sfnStandardTopMargin">
Save to server successful
</div>
Write this -
//div[@id='alertLabel' and text()='Save to server successful']
这篇关于Selenium 和 xpath:找到一个带有 class/id 的 div 并验证里面的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文