[英]Selenium webdriver with C#
I am new to selenium webdriver and getting some problems.我是 selenium webdriver 的新手,遇到了一些问题。
Can any of you give me idea on How to select an item from a drop down list using Selenium webdriver with C#.你们中的任何人都可以告诉我如何使用带有 C# 的 Selenium webdriver 从下拉列表中选择一个项目。
you can try like this...你可以试试这样...
SelectElement select = new SelectElement(dropdownobject);
select.SelectByText("ItemText");
Two ways are there有两种方式
driver.FindElement(By.XPath(".//*@id='steppersonalInfo']/div[2]/div[1]/div[1]/div")).Click();
driver.FindElement(By.XPath(".//[@id='steppersonalInfo']/div[2]/div[1]/div[1]/ul/li[4]")).Click();
And Another way is另一种方法是
IWebElement Month = driver.FindElement(By.XPath(".//*[@id='ui-datepicker-div']/div/div/select[1]"));
SelectElement clickmonth = new SelectElement(Month);
clickmonth.SelectByText("May");
There are multiple predefined functions in Select class to get items from drop down in selenium. Select 类中有多个预定义函数可以从 selenium 的下拉列表中获取项目。
SelectElement select = new SelectElement(dropdownobject);
1) select.selectByVisibleText("ItemText");
OR
2) select.selectByIndex(1);
I hope this can help you:我希望这可以帮助你:
protected void SelectDropDown(By locator, string type, string textOrValueOrIndex)
{
SelectElement select = new SelectElement(driver.FindElement(locator));
switch (type)
{
case "text":
select.SelectByText(textOrValueOrIndex);
break;
case "value":
select.SelectByValue(textOrValueOrIndex);
break;
case "index":
select.SelectByIndex(Convert.ToInt32(textOrValueOrIndex));
break;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.