java - 验证购物车中可用的产品,然后使用删除链接 a 使用 selenium Java 删除。这里的产品数量未知
问题描述
java中的selenium脚本检查购物车中可用的产品,如果可用,则使用删除链接删除。
for(int i = result; i >= 0; i--) {
boolean str = "Product available with remove link";
if(str) {
// Click on remove link till remove link there to remove all product
}
else {
// Verify no product present Text
}
}
这里的问题 Loop 只运行一次并且只删除一个产品。每个产品都有相关的删除链接。我们不知道购物车中列出的产品数量。所以我们必须删除所有这些。如果不可用,则显示消息产品未列出。
解决方案
在if
.
public void removeProducts() {
List<WebElement> removeProductBtnList = driver.findElements(locator);
for (WebElement removeProductBtn : removeProductBtnList ) {
driver.findElement(locator).click();
//removeProductBtn.click(); you can also use this line instead of the above,
//but it will probably return a StaleElementReferenceException after the first click.
}
}
如果购物车上没有 removeButtons,则此方法不执行任何操作。
推荐阅读
- javascript - 当我添加 json 文件时,Angular 8 不在 rootDir 下
- javascript - 在 django 中使用 const 变量
- python - 创建几个新的连接字符串列——如何制作 pythonic?
- git - 在 Netbeans 中配置 git
- android - 使用 Firebase 和 Flutter 的多租户 SaaS 应用
- css - 未设置 css 数值变量
- javascript - 如何在边界框内放置文本?
- node.js - MongooseError [MissingSchemaError]:模式尚未注册模型“评论”
- excel - 无法找出 Excel VBA 代码的问题
- java - 如何使用命令创建java项目?