Reputation: 31
I am trying to make a method that returns at the same time, two elements. This is my code:
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"));
But I don't know how to make it right...Can you please help me. Thank you in advance!!!
Upvotes: 0
Views: 54
Reputation: 613
I am not sure if the following syntax is correct.
return this.Driver.FindElements(By.Id("mm_date_8"), By.Id("dd_date_8"));
instead what you can try to do is following.
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, IEnumerable<IWebElement> elementEnumerable)
{
if (elementEnumerable != null && elementEnumerable.Any())
{
elementList.AddRange(elementEnumerable);
}
}
Please note, I am assuming output of FindElements
is IEnumerable
. But if its other type of collection, the idea still remains the same.
If you must know what element belongs to what ID you can instead of creating a list can create a
Dictionary<string, IWebElement>
where string would be your idKey
.
Upvotes: 1