简体   繁体   English

将字符串列表与 webelements 列表进行比较

[英]Compare list of string with list of webelements

For sure it's trivial case but I'm having list of webelements and array of strings.当然这是微不足道的情况,但我有 webelements 列表和字符串数组。 I need to check if list of webelements contains string inside that array.我需要检查 webelements 列表是否包含该数组中的字符串。

public IList<IWebElement> PaymentNames => driver.WaitForElementsVisible(By.XPath(paymentNameLocator));
string[] expectedPaymentNames = {"Cash","Card"};

    public bool ArePaymentNamesCorrectlyShown(string[] paymentNames)
    {
       return  PaymentNames.Any(t => t.Text == ????);
    }

I was trying to do it by linqu but no idea how to compare it with array...我试图通过 linqu 来做,但不知道如何将它与数组进行比较......

You are pretty close.你很接近。 You cannot compare t.Text to one thing.您不能将t.Text与一件事进行比较。 You need to see if the text is contained in the expected payment names:您需要查看文本是否包含在预期的付款名称中:

return PaymentNames.Any(t => paymentNames.Contains(t.Text));

This particular Contains(...) method is in the System.Linq namespace, which you should already be using in this C# file.这个特定的Contains(...)方法位于 System.Linq 命名空间中,您应该已经在此 C# 文件中使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM