I have a method I want to be able to return a list of IWebElements, a list of just the names of the elements or a string array. Is it possible to return multiple data types with one method? Is there a more feasible way to get the different return types without using just one method?
/// <summary>
/// Gets all options belonging to this selected tag
/// </summary>
/// <returns>Returns a list of IWebElements</returns>
public List<IWebElement> SelectAllOptions(IWebDriver driver, ref DataObject masterData)
{
//Get the ID of the dropdown menu
DatabaseRetrieval.GetObjectRepository(ref masterData);
var strDropMenuId = masterData.DictObjectRepository["ID"];
//Find the dropdown menu and pull all options into a list
try
{
var dropMenu = new SelectElement(driver.FindElement(By.Id(strDropMenuId)));
return dropMenu.Options as List<IWebElement>;
}
catch (NoSuchElementException exception)
{
masterData.Logger.Log(Loglevel.Error, "Boom: {0}", exception.Message);
}
masterData.Logger.Log(Loglevel.Debug, "No options found for DropDownMenu: {0}", strDropMenuId);
return null;
}
You can't return multiple types. You can however:
Tuple insteadBut that's a very bad design decision and you should really consider avoiding it. (It usually means your method does more than it should)
Yes but You have to use the out paramaters like the following
public List<IWebElement> SelectAllOptions(IWebDriver driver, ref DataObject masterData, out SomeType returnResult1, out SomeType returnResult2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With