Skip to content

Commit 0c6367f

Browse files
authored
Fixes for setting DateTime fields in Header (#986)
1 parent 88ca87a commit 0c6367f

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs

+6-12
Original file line numberDiff line numberDiff line change
@@ -2696,13 +2696,6 @@ private bool TrySetValue(IWebDriver driver, ISearchContext container, DateTimeCo
26962696
TrySetDateValue(driver, container, control, formContext);
26972697
TrySetTime(driver, container, control, formContext);
26982698

2699-
if (container is IWebElement parent)
2700-
{
2701-
parent.Click(true);
2702-
parent.SendKeys(Keys.Escape); // Close Calendar
2703-
parent.SendKeys(Keys.Escape); // Close Header control
2704-
}
2705-
27062699
TryCloseHeaderFlyout(driver);
27072700

27082701
return true;
@@ -2790,27 +2783,27 @@ private static void TrySetTime(IWebDriver driver, ISearchContext container, Date
27902783
//IWebDriver formContext;
27912784
// Initialize the quick create form context
27922785
// If this is not done -- element input will go to the main form due to new flyout design
2793-
formContext = container.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.QuickCreate.QuickCreateFormContext]));
2786+
formContext = container.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.QuickCreate.QuickCreateFormContext]), new TimeSpan(0,0, 1));
27942787
}
27952788
else if (formContextType == FormContextType.Entity)
27962789
{
27972790
// Initialize the entity form context
2798-
formContext = container.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.Entity.FormContext]));
2791+
formContext = container.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.Entity.FormContext]), new TimeSpan(0, 0, 1));
27992792
}
28002793
else if (formContextType == FormContextType.BusinessProcessFlow)
28012794
{
28022795
// Initialize the Business Process Flow context
2803-
formContext = container.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.BusinessProcessFlow.BusinessProcessFlowFormContext]));
2796+
formContext = container.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.BusinessProcessFlow.BusinessProcessFlowFormContext]), new TimeSpan(0, 0, 1));
28042797
}
28052798
else if (formContextType == FormContextType.Header)
28062799
{
28072800
// Initialize the Header context
2808-
formContext = container.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.Entity.HeaderContext]));
2801+
formContext = container as IWebElement;
28092802
}
28102803
else if (formContextType == FormContextType.Dialog)
28112804
{
28122805
// Initialize the Header context
2813-
formContext = container.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.Dialogs.DialogContext]));
2806+
formContext = container.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.Dialogs.DialogContext]), new TimeSpan(0, 0, 1));
28142807
}
28152808

28162809
var success = formContext.TryFindElement(timeFieldXPath, out var timeField);
@@ -2831,6 +2824,7 @@ private static void TrySetTime(IWebDriver driver, IWebElement timeField, string
28312824
timeField.Click();
28322825
timeField.SendKeys(time);
28332826
timeField.SendKeys(Keys.Tab);
2827+
driver.WaitForTransaction();
28342828
},
28352829
d => timeField.GetAttribute("value").IsValueEqualsTo(time),
28362830
TimeSpan.FromSeconds(9), 3,

Microsoft.Dynamics365.UIAutomation.Browser/Extensions/SeleniumExtensions.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,18 @@ public static IWebElement FindClickable(this ISearchContext driver, By locator)
428428

429429
public static bool TryFindElement(this ISearchContext context, By by, out IWebElement element)
430430
{
431-
var elements = context.FindElements(by);
432-
var success = elements.Count > 0;
431+
ReadOnlyCollection<IWebElement> elements = null;
432+
433+
try
434+
{
435+
elements = context.FindElements(by);
436+
}
437+
catch (NullReferenceException)
438+
{
439+
// Do nothing
440+
}
441+
442+
var success = elements?.Count > 0;
433443
element = success ? elements[0] : null;
434444
return success;
435445
}

0 commit comments

Comments
 (0)