简体   繁体   English

如何验证 selenium c# 下拉列表中的所有值

[英]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" }; {“服务顾问”、“DLBO 开发人员”、“管理员代理”、“团队负责人”、“经理”、“CV 委托人”、“CV 代理”、“取证代理”};

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您可以将值存储到列表中,并将其与列表或 json 文件中保存的现有数据进行比较

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);

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

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