简体   繁体   中英

How to Verify all values from DropDown List in selenium c#

I have the below values inside the dropdown and i need to very each values in the dropdown.

{ "Service Consultant", "DLBO Developer", "Admin Agent", "Team Leader", "Manager", "CV Mandator", "CV Agent", "Forensics Agent" };

Kindly suggest the way to do the same.

You can store the values into a list and compare it with already existing data kept in a list or a json file

var expectedDdOptions = new string[] { "Service Consultant", "DLBO Developer", "Admin Agent", "Team Leader", "Manager", "CV Mandator", "CV Agent", "Forensics Agent" };
var ActualDdOptions = new SelectElement(driver.FindElementById("YourDropdownLocatorId")).Options; //SelectElement class comes from OpenQA.Selenium.Support.UI namespace
Assert.AreEqual(expectedDdOptions.Length, ActualDdOptions.Count());
var invalidOptInDd = from e in ActualDdOptions
                     where !expectedDdOptions.Contains(e.Text)
                     select e;
Assert.IsEmpty(invalidOptInDd,"Invalid options in dropdown - " + invalidOptInDd);

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