in Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs [2021:2104]
public BrowserCommandResult<bool> ClickSubGridCommand(string subGridName, string name, string subName = null, string subSecondName = null)
{
return this.Execute(GetOptions("Click SubGrid Command"), driver =>
{
// Initialize required local variables
IWebElement subGridCommandBar = null;
// Find the SubGrid
var subGrid = driver.FindElement(By.XPath(AppElements.Xpath[AppReference.Entity.SubGridContents].Replace("[NAME]", subGridName)));
if (subGrid == null)
throw new NotFoundException($"Unable to locate subgrid contents for {subGridName} subgrid.");
// Check if grid commandBar was found
if (subGrid.TryFindElement(By.XPath(AppElements.Xpath[AppReference.Entity.SubGridCommandBar].Replace("[NAME]", subGridName)), out subGridCommandBar))
{
//Is the button in the ribbon?
if (subGridCommandBar.TryFindElement(By.XPath(AppElements.Xpath[AppReference.Entity.SubGridCommandLabel].Replace("[NAME]", name)), out var command))
{
command.Click(true);
driver.WaitForTransaction();
}
else
{
// Is the button in More Commands overflow?
if (subGridCommandBar.TryFindElement(By.XPath(AppElements.Xpath[AppReference.Entity.SubGridCommandLabel].Replace("[NAME]", "More Commands")), out var moreCommands))
{
// Click More Commands
moreCommands.Click(true);
driver.WaitForTransaction();
// Locate the overflow button (More Commands flyout)
var overflowContainer = driver.FindElement(By.XPath(AppElements.Xpath[AppReference.Entity.SubGridOverflowContainer]));
//Click the primary button, if found
if (overflowContainer.TryFindElement(By.XPath(AppElements.Xpath[AppReference.Entity.SubGridOverflowButton].Replace("[NAME]", name)), out var overflowCommand))
{
overflowCommand.Click(true);
driver.WaitForTransaction();
}
else
throw new InvalidOperationException($"No command with the name '{name}' exists inside of {subGridName} Commandbar.");
}
else
throw new InvalidOperationException($"No command with the name '{name}' exists inside of {subGridName} CommandBar.");
}
if (subName != null)
{
// Locate the sub-button flyout if subName present
var overflowContainer = driver.FindElement(By.XPath(AppElements.Xpath[AppReference.Entity.SubGridOverflowContainer]));
//Click the primary button, if found
if (overflowContainer.TryFindElement(By.XPath(AppElements.Xpath[AppReference.Entity.SubGridOverflowButton].Replace("[NAME]", subName)), out var overflowButton))
{
overflowButton.Click(true);
driver.WaitForTransaction();
}
else
throw new InvalidOperationException($"No command with the name '{subName}' exists under the {name} command inside of {subGridName} Commandbar.");
// Check if we need to go to a 3rd level
if (subSecondName != null)
{
// Locate the sub-button flyout if subSecondName present
overflowContainer = driver.FindElement(By.XPath(AppElements.Xpath[AppReference.Entity.SubGridOverflowContainer]));
//Click the primary button, if found
if (overflowContainer.TryFindElement(By.XPath(AppElements.Xpath[AppReference.Entity.SubGridOverflowButton].Replace("[NAME]", subSecondName)), out var secondOverflowCommand))
{
secondOverflowCommand.Click(true);
driver.WaitForTransaction();
}
else
throw new InvalidOperationException($"No command with the name '{subSecondName}' exists under the {subName} command inside of {name} on the {subGridName} SubGrid Commandbar.");
}
}
}
else
throw new InvalidOperationException($"Unable to locate the Commandbar for the {subGrid} SubGrid.");
return true;
});
}