两个值之间的硒比较失败 [英] Selenium ComparisonFailure between 2 value

查看:34
本文介绍了两个值之间的硒比较失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码:

    List<WebElement> ProductPrices1 = driver.findElements(By.className("prc-slg"));
    String text1Price = ProductPrices1.get(0).getText();
    
    thread(1500);
    element(ClickBucket).click();
    thread(1500);

    
    List<WebElement> elements = driver.findElements(By.xpath("//div[contains(@class, 'pb-basket-item-price')]"));
    for (WebElement element : elements) {
        str = element.getText();

        int cntTL = (str.length() - str.replace("TL", "").length()) / 2;
        if (2 == cntTL) {
            str = str.split("TL")[1].replace("\"", "") + " TL";
        }
      
    }
    
    System.out.println("first value : "+text1Price+"Bucket Value : "+str);
     Assert.assertEquals(text1Price,str);

结果如下:

第一个值:1.189 TL 桶值:
1.189 TL
基础
失败:signInTestCase
org.junit.ComparisonFailure:预期:<[1.189] TL>但是是:<[
1.189 ] TL>

This is the result:

first value : 1.189 TL Bucket Value :
1.189 TL
basarisiz
FAILED: signInTestCase
org.junit.ComparisonFailure: expected:<[1.189] TL> but was:<[
1.189 ] TL>

推荐答案

有几种方法可以解决这个问题.其中之一是:

There are several ways to solve the problem. One of them is:

Assert.assertEquals(text1Price.replace("TL", "").trim(), str.replace("TL", "").trim());

这篇关于两个值之间的硒比较失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆