java 检查列表中的元素是否在WebElement文本中可见

f87krz0w  于 2023-05-21  发布在  Java
关注(0)|答案(1)|浏览(102)

我有一个非常简单和愚蠢的情况下,我不能正确处理:
总体思路:

  • 列出包含地址元素的字符串(如:姓名、街道等)
  • 在DOM上获取包含所有这些数据的WebElement
  • 循环遍历列表并比较特定的列表元素是否包含在taken WebElement中

创建字符串列表:

List<String> accountBillingAddressData = new ArrayList<>(List.of("Mevrouw","Jan Kowalski", "testStreet","15","1234567","1234WW","Amsterdam","Nederland"));

获取WebElement文本:

String billingAddress = StringUtils.normalizeSpace(baseMethods.findElement("CheckoutPage.Billing.Section").getText());

“findElements”名称被 Package 在框架中。
DOM元素看起来像:

<div class="address" bis_skin_checked="1">
  <p>
    Mevrouw Jan Kowalski<br>
    testStreet 15<br>
    1234567<br>
    1234WW Amsterdam
    <br> Nederland
  </p>
</div>

定位器为:.address > p
验证码:

List<String> accountBillingAddressData = new ArrayList<>(List.of("Mevrouw","Jan Kowalski", "testStreet","15","1234567","1234WW","Amsterdam","Nederland"));
String billingAddress = StringUtils.normalizeSpace(baseMethods.findElement("CheckoutPage.Billing.Address").getText());
for (String addressElement : accountBillingAddressData){
    if(!billingAddress.contains(addressElement));
    {
        Assert.fail("Billing address does not contain specific data");
    }
}

列表和WebElement中的数据看起来也是正确的。然而,如果循环继续在内部运行并失败....

f45qwnt8

f45qwnt81#

更新:if里面有错误:

if(!billingAddress.contains(addressElement));
    {
        Assert.fail("Billing address does not contain specific data");
    }

它应该是:

if(!billingAddress.contains(addressElement)){
        Assert.fail("Billing address does not contain specific data");
    }

相关问题