简体   繁体   中英

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. I need to check if list of webelements contains string inside that array.

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...

You are pretty close. You cannot compare t.Text to one thing. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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