这是我想要自动化的代码:
<span class="select2-selection select2-selection--single" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-labelledby="select2-selection-class-dropdown-container"><span class="select2-selection__rendered" id="select2-selection-class-dropdown-container" title="Search">Search</span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span>
它正在工作!!
Select mydrpdwn1 = new Select(driver.findElement(By.id("selection-division-dropdown")));
mydrpdwn1.selectByVisibleText("division A");
public void selectOption(text)
{
IWebElement _webElement = Drivers._driverInstance.FindElement(By.Name("ID of your dropdown"));
SelectElement ddloptions = new SelectElement(_webElement);
ddloptions.SelectByText(text);
}
要从下拉列表中获取所选选项,请执行以下操作:
public static string GetServiceUserDropdown()
{
IWebElement _webElement = Drivers._driverInstance.FindElement(By.Name("Id of dropdown"));
SelectElement selectedvalue = new SelectElement(_webElement);
return selectedvalue.SelectedOption.Text;
}
希望这有帮助。代码是 C#