2017-04-09 78 views
0

我正在嘗試使兩個元素同時返回的方法。這是我的代碼:返回多個元素的斷言器

this.Wait.Until(ExpectedConditions.ElementExists(By.Id("mm_date_8"))); 
this.Wait.Until(ExpectedConditions.ElementExists(By.Id("dd_date_8"))); 

return this.Driver.FindElements(By.Id("mm_date_8"), By.Id("dd_date_8")); 

但我不知道如何使它正確...你能幫我。 提前謝謝!

回答

1

我不確定以下語法是否正確。

​​

取而代之的是你可以嘗試做下面的事情。

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。