![](/img/trans.png)
[英]SELENIUM & JAVA - Ecommerce Application - Unable to remove product from the cart page
[英]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.