我需要幫助,如何從下拉列表中選擇一個值,我正在編程C#
與Selenium
,並且我總是收到以下錯誤:如何從下拉列表中選擇值(Selenium C#)
Element should have been select but was span
我的代碼是:
internal static void SelectDD()
{
SelectElement xxx= new SelectElement(driver.FindElement(By.XPath("/html/body/div[1]/section/div[1]/div[2]/section/div/section/div[2]/div[2]/div/div[2]/div[1]/div/div[2]/div/div/a/span[1]")));
xxx.SelectByIndex(1);
}
HTML:
<span class="select2-hidden-accessible" role="status" aria-live="polite"></span> <span class="select2-hidden-accessible" role="status" aria-live="polite"></span> <span class="select2-hidden-accessible" role="status" aria-live="polite"></span>
<div id="select2-drop-mask" class="select2-drop-mask" style="display: block;"></div>
<div id="select2-drop" class="select2-drop select2-display-none select2-drop-auto-width select2-drop-active select2-drop-above" style="left: 361.583px; top: 472.1px; bottom: auto; display: block; width: 262px;"></div>
</body>
HTML : 的
*** ***