如何从下拉菜单中选择一个值?

时间:2019-05-15 08:17:32

标签: c# selenium selenium-webdriver

我似乎有不同类型的HTML下拉列表,因此无法使用Selenium Webdriver从中选择一个值。如何使SelectElement下拉,以便可以使用SelectElement.SelectByValue?

我尝试了以下操作,但收到错误消息

IWebElement qualification = driver.FindElement(By.Id("qual")); SelectElement qSelect = new SelectElement(qualification)

这是HTML

<div>
   <inv-drop-down-select [width]="268" identifier="qualification" id="qual" formControlName="Qualification" [items]="qualifications">
   </inv-drop-down-select>
</div>

我试图做到这一点

IWebElement qualification = driver.FindElement(By.Id("qual"));
SelectElement qSelect = new SelectElement(qualification)

我收到以下错误

OpenQA.Selenium.Support.UI.UnexpectedTagNameException:'元素应已选择,但已inv-drop-down-select'

HTML是

<span _ngcontent-wiv-c81="">Please Select...</span> <li _ngcontent-wiv-c81="" role="menuitem" class="ng-star-inserted"><a _ngcontent-wiv-c81="" class="selected"><span _ngcontent-wiv-c81="">Masters</span></a></li> <li _ngcontent-wiv-c81="" role="menuitem" class="ng-star-inserted"><a _ngcontent-wiv-c81=""><span _ngcontent-wiv-c81="">Degree</span></a></li>

0 个答案:

没有答案