我不確定以下語法是否正確。
取而代之的是你可以嘗試做下面的事情。
List<IWebElement> elements = new List<IWebElement>();
AddElementsToList(elements, this.Driver.FindElements(By.Id("mm_date_8"));
AddElementsToList(elements, this.Driver.FindElements(By.Id("dd_date_8"));
// now in your calling method you can easily index list.
return elements;
public void AddElementsToList(List<IWebElement> elementList, IEnumberable<IWebElement> elementEnumerable)
{
if (elementEnumerable != null && elementEnumerable.Any())
{
elementList.AddRange(elementEnumerable);
}
}
請注意,我假設FindElements的輸出是IEnumerable。但是如果它的其他類型的收藏,這個想法仍然是一樣的。
如果你一定要知道的元素屬於什麼可以代替創建列表可以創造什麼ID的
Dictionary<string, IWebElement>
其中的字符串將是你的idKey。