更新时间:2023-09-01 10:41:10
您可以尝试使用在 OpenQA.Selenium.Support.UI.Selected 中找到的WebDriver.Support SelectElement . >名称空间以访问选择列表的选项列表:
You can try using the WebDriver.Support SelectElement found in OpenQA.Selenium.Support.UI.Selected namespace to access the option list of a select list:
IWebElement elem = driver.FindElement(By.XPath("//select[@name='time_zone']"));
SelectElement selectList = new SelectElement(elem);
IList<IWebElement> options = selectList.Options;
然后您可以将每个选项作为IWebElement进行访问,例如:
You can then access each option as an IWebElement, such as:
IWebElement firstOption = options[0];
Assert.AreEqual(firstOption.GetAttribute("value"), "-09:00");