简体   繁体   English

SELENIUM JAVA-验证字符串的部分内容

[英]SELENIUM JAVA - Verify partial content of a string

I would like to verify the partial value of a string I get from a web page. 我想验证从网页获取的字符串的部分值。 I give an example the string is "Incident 1946721 Updated" and I would like to insert a check that verifies that the two words Incident are present as prefix and Updated as suffix. 我举一个例子,字符串是“ Incident 1946721 Updated”,我想插入一个检查,以验证“ Incident”这两个词是否作为前缀出现,“ Updated”作为后缀。 how can I do? 我能怎么做?

the html code where the text is present this is: 文本所在的html代码是:

<div class="modal-body"><button type="button" class="bootbox-close-button close" data-dismiss="modal" aria-hidden="true" style="margin-top: -10px;">×</button><div class="bootbox-body">Incident 1946721 Updated</div></div>

Use below code : 使用以下代码:

String value = driver.findElement(By.xpath("//div[@class='bootbox-body']")).getText();

if(value.startsWith("Incident") && value.endsWith("Updated")) {
    System.out.println("Test Pass");
}else {
    System.out.println("Test Fail");
}

Let me know if you have further query. 让我知道您是否还有进一步的查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM