验证购物车中提供的产品,然后使用selenium Java删除链接a。这里的产品数量未知

问题描述 投票:-1回答:1

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 
   }
}

这里的问题循环只运行一次,只删除一个产品。每个产品都有关联的删除链接。我们不知道购物车中列出的产品数量。所以我们必须删除所有这些。如果不可用,则显示未列出的消息产品。

java selenium for-loop conditional base
1个回答
0
投票

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,则此方法不执行任何操作。

© www.soinside.com 2019 - 2024. All rights reserved.