java - SELENIUM JAVA - 验证字符串的部分内容
问题描述
我想验证从网页获得的字符串的部分值。我举了一个例子,字符串是“Incident 1946721 Updated”,我想插入一个检查,验证这两个单词 Incident 作为前缀存在,Updated 作为后缀。我能怎么做?
文本所在的 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>
解决方案
使用以下代码:
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");
}
如果您有进一步的疑问,请告诉我。
推荐阅读
- python - 张量流中的 tf.checkpoint.save() 和 tf.checkpointmanager.save() 有什么区别?
- bots - Slack bot 请求验证不适用于按钮操作。如果我们在块套件 U 中有粗体格式标记 *
- angular - 组件正在路由器出口外加载
- java - 我的循环继续运行我想运行一次的特定方法
- javascript - ajax 将 null 发送到 MVC Api 控制器
- python - 根据日期列取列到行
- swift - 使用 FirebaseUI 身份验证删除用户帐户时出错。服务
- python - 在理解中合并和添加字典值
- arrays - 存储、索引支持高维(2048)特征向量
- java - 在使用 github 的 dozermapper 时在字段上使用带有“this”值(@Mapping("this"))的映射注释的使用