簡體   English   中英

驗證產品在購物車中可用,然后使用刪除鏈接 a 使用 selenium Java 刪除。 這里的產品數量未知

[英]Verify Product available in shopping cart then remove using remove link a using selenium Java . Here number of product is unknown

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM