in Microsoft.Dynamics365.UIAutomation.Api/XrmPage.cs [1082:1181]
public BrowserCommandResult<bool> SetValue(CompositeControl control, bool checkForDialog = false, [Range(1, 10)]int index = 1)
{
return this.Execute(GetOptions($"Set ConpositeControl Value: {control.Id}"), driver =>
{
driver.WaitUntilVisible(By.Id(control.Id));
if (!driver.HasElement(By.Id(control.Id)))
return false;
driver.ClickWhenAvailable(By.Id(control.Id));
if (driver.HasElement(By.Id(control.Id + Elements.ElementId[Reference.SetValue.FlyOut])))
{
var compcntrl =
driver.FindElement(By.Id(control.Id + Elements.ElementId[Reference.SetValue.FlyOut]));
// Initialize i, to correspond with current field position in control.Fields
int i = 0;
foreach (var field in control.Fields)
{
compcntrl.FindElement(By.Id(control.Id + Elements.ElementId[Reference.SetValue.CompositionLinkControl] + field.Id)).Click(true);
var result = compcntrl.FindElements(By.TagName("input"))
.ToList()
.FirstOrDefault(x => x.GetAttribute("id").Contains(field.Id));
if (checkForDialog)
{
if (IsDialogFrameVisible())
{
if (control.Fields.Count == (i + 1))
{
SwitchToDialog();
var addressSuggestor = driver.FindElement(By.Id("ctrAddressSuggestor"));
var suggestedAddresses = addressSuggestor.FindElements(By.TagName("li"));
var targetAddress = suggestedAddresses[(index - 1)].FindElement(By.TagName("a"));
targetAddress.Click(true);
SwitchToContentFrame();
compcntrl = driver.WaitUntilAvailable(By.Id(control.Id + Elements.ElementId[Reference.SetValue.FlyOut]));
compcntrl.FindElement(By.Id(control.Id + Elements.ElementId[Reference.SetValue.Confirm])).Click(true);
return true;
}
else
{
SwitchToDialog();
var closeFoundPlaces = driver.FindElement(By.XPath(Elements.Xpath[Reference.Dialogs.CloseFoundPlacesDialog]));
closeFoundPlaces.Click(true);
SwitchToContentFrame();
}
}
else
SwitchToContentFrame();
}
driver.WaitUntilAvailable(By.Id(control.Id + Elements.ElementId[Reference.SetValue.CompositionLinkControl] + field.Id));
compcntrl.FindElement(By.Id(control.Id + Elements.ElementId[Reference.SetValue.CompositionLinkControl] + field.Id)).Click(true);
//BugFix - Setvalue -The value is getting erased even after setting the value ,might be due to recent CSS changes.
driver.ExecuteScript("document.getElementById('" + result?.GetAttribute("id") + "').value = ''");
result?.SendKeys(field.Value);
i++;
}
compcntrl.FindElement(By.Id(control.Id + Elements.ElementId[Reference.SetValue.Confirm])).Click(true);
// Repeat this check in the event the Found Places dialog appears after closing the Composite Control for Address
if (checkForDialog)
{
if (IsDialogFrameVisible())
{
if (control.Fields.Count == (i + 1))
{
SwitchToDialog();
var addressSuggestor = driver.FindElement(By.Id("ctrAddressSuggestor"));
var suggestedAddresses = addressSuggestor.FindElements(By.TagName("li"));
var targetAddress = suggestedAddresses[(index - 1)].FindElement(By.TagName("a"));
targetAddress.Click(true);
SwitchToContentFrame();
}
}
}
}
else
throw new InvalidOperationException($"Composite Control: {control.Id} Does not exist");
return true;
});
}