selenium select 标签选中

public static int SetSelectedIndex(this IWebDriver webdriver, string selector, int selectedIndex)
{
SelectElement element = new SelectElement(webdriver.FindElement(By.CssSelector(selector)));
if (selectedIndex >= element.Options.Count)
selectedIndex = 0;
element.SelectByIndex(selectedIndex);
return -1;
}

select 标签的用处还是很多的,数据页面都会有,所以有必要把这个方法保存下来,以后整理成扩展方法。

原文地址:https://www.cnblogs.com/wcLT/p/3421847.html