我只有一个疑问!
我想问一下,在自动化测试中,当产品添加到购物车时,我们是否可以选择检查折扣计算。下面是我问题的情景:
当我们进入结账页面时,将折扣产品添加到购物车系统,根据折扣百分比检查产品价格是否正确。如果价格正确,则继续。4.折扣显示在网站上。网址:https://focusclothing.pk/collections/men
我的代码在这里:
WebElement popup_close = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[4]/div/div[2]/div[4]/div/div/button")));
popup_close.click();
WebElement sale = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[3]/div[1]/div/div[2]/div/div/div/nav/ul/li[8]/a")));
sale.click();
List<WebElement> product_list = driver.findElements(By.xpath("/html/body/div[3]/div[2]/div/div/div[8]/div[1]"));
for (WebElement items_product : product_list) {
System.out.println(items_product.getText());
}
System.out.println("Original Price of Items");
List<WebElement> Original_price = driver.findElements(By.className("was"));
System.out.println(Original_price.size());
for(int i=0; i<Original_price.size(); i++) {
List<String> Original_price_1st = new ArrayList<String>();
Original_price_1st.add(Original_price.get(i).getText());
System.out.println(Original_price.get(i).getText());
}
System.out.println("Discounted Price of items");
List<WebElement> Discounted_price=driver.findElements(By.className("onsale"));
System.out.println(Discounted_price.size());
for(int i=0; i<Original_price.size();i++)
{
List<String> Discounted_price_lst = new ArrayList<String>();
Discounted_price_lst.add(Discounted_price.get(i).getText());
System.out.println(Discounted_price.get(i).getText());
}
for(int i=0;i<Discounted_price.size();i++) {
List<String> Original_price_lst_1 = new ArrayList<String>();
List<String> Discounted_price_lst_1 = new ArrayList<String>();
String original_price_removecurrencysymbol = Original_price.get(i).getText().substring(3,Original_price.get(i).getText().length());
String discount_price_removecurrencysymbol = Discounted_price.get(i).getText().substring(3,Discounted_price.get(i).getText().length());
System.out.println(original_price_removecurrencysymbol);
System.out.println(discount_price_removecurrencysymbol);
double difference = Double.valueOf(original_price_removecurrencysymbol) - Double.valueOf(discount_price_removecurrencysymbol);
System.out.println("Difference is:"+difference);
}
我面临的错误截图:https://prnt.sc/18yvejc 在此之前,我的代码可以找到原价和折扣价。此外,我编写了代码来查找价格之间的差异,但出现了一个错误。找到价格差异后,我想根据折扣百分比检查差异是否正确。
1条答案
按热度按时间q8l4jmvw1#
进入折扣页面后:
您可以使用以下代码(此代码仅适用于您在共享url上看到的第一个web元素、图像或产品):
更新1:
要获得所有这些,请执行以下操作:
我的本地机器输出:
=============