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
}
}
这里的问题循环只运行一次,只删除一个产品。每个产品都有关联的删除链接。我们不知道购物车中列出的产品数量。所以我们必须删除所有这些。如果不可用,则显示未列出的消息产品。
在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,则此方法不执行任何操作。