in Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs [3053:3114]
private BrowserCommandResult<bool> AddMultiOptions(MultiValueOptionSet option, FormContextType formContextType)
{
return this.Execute(GetOptions($"Add Multi Select Value: {option.Name}"), driver =>
{
IWebElement fieldContainer = null;
if (formContextType == FormContextType.QuickCreate)
{
// Initialize the quick create form context
// If this is not done -- element input will go to the main form due to new flyout design
var formContext = driver.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.QuickCreate.QuickCreateFormContext]));
fieldContainer = formContext.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.MultiSelect.DivContainer].Replace("[NAME]", option.Name)));
}
else if (formContextType == FormContextType.Entity)
{
// Initialize the entity form context
var formContext = driver.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.Entity.FormContext]));
fieldContainer = formContext.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.MultiSelect.DivContainer].Replace("[NAME]", option.Name)));
}
else if (formContextType == FormContextType.BusinessProcessFlow)
{
// Initialize the Business Process Flow context
var formContext = driver.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.BusinessProcessFlow.BusinessProcessFlowFormContext]));
fieldContainer = formContext.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.MultiSelect.DivContainer].Replace("[NAME]", option.Name)));
}
else if (formContextType == FormContextType.Header)
{
// Initialize the Header context
var formContext = driver.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.Entity.HeaderContext]));
fieldContainer = formContext.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.MultiSelect.DivContainer].Replace("[NAME]", option.Name)));
}
else if (formContextType == FormContextType.Dialog)
{
// Initialize the Header context
var formContext = driver.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.Dialogs.DialogContext]));
fieldContainer = formContext.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.MultiSelect.DivContainer].Replace("[NAME]", option.Name)));
}
var inputXPath = By.XPath(AppElements.Xpath[AppReference.MultiSelect.InputSearch]);
fieldContainer.FindElement(inputXPath).SendKeys(string.Empty);
var flyoutCaretXPath = By.XPath(AppElements.Xpath[AppReference.MultiSelect.FlyoutCaret]);
fieldContainer.FindElement(flyoutCaretXPath).Click();
foreach (var optionValue in option.Values)
{
var flyoutOptionXPath = By.XPath(AppElements.Xpath[AppReference.MultiSelect.FlyoutOption].Replace("[NAME]", optionValue));
if (fieldContainer.TryFindElement(flyoutOptionXPath, out var flyoutOption))
{
var ariaSelected = flyoutOption.GetAttribute<string>("aria-selected");
var selected = !string.IsNullOrEmpty(ariaSelected) && bool.Parse(ariaSelected);
if (!selected)
{
flyoutOption.Click();
}
}
}
return true;
});
}