// //美国
copy selector = #ddlCountries
Select drpCountries = new Select(driver.findElement(By.id("ddlCountries")));
drpCountries.selectByValue("999");
我一直收到此错误,没有这样的元素:无法找到元素:{"method":"id","selector":"ddlCountries"}
答案 0 :(得分:0)
使用SelectOptionInList(“ ddlCountries”,“ 999”);
public IWebDriver SelectOptionInList(string elementID, string optionValue)
{
SelectElement ElementSelect = new SelectElement(driver.FindElement(By.Id(elementID)));
IList<IWebElement> ElementList = ElementSelect.Options;
int ElementCount = ElementList.Count;
for (int i = 0; i < ElementCount; i++)
{
string elementText = ElementList.ElementAt(i).Text;
if (elementText.Equals(optionValue))
{
ElementList.ElementAt(i).Click();
Console.WriteLine("Option " + optionValue + "Clicked");
return driver;
}
else if(elementText.Contains(optionValue))
{
ElementList.ElementAt(i).Click();
Console.WriteLine("Option " + optionValue + "Clicked");
return driver;
}
else
{
Console.WriteLine("Option " + optionValue + " Not Found Under Element with ID: " + elementID);
}
}
return driver;
}