From d38f81d76330da8eae5ebbabf8143b9be1785e91 Mon Sep 17 00:00:00 2001 From: Jason Lattimer Date: Fri, 17 May 2019 09:12:44 -0400 Subject: [PATCH] GitHub issue #371 Updated SetValue for lookup. Added a WaitForTransaction to ensure the page is loaded to prevent issue with SetValue executing when the load is still happening. Added sleeps to make sure the elements get hovered & clicked properly (#480) --- .../DTO/AppElementReference.cs | 4 ++++ .../WebClient.cs | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Microsoft.Dynamics365.UIAutomation.Api.UCI/DTO/AppElementReference.cs b/Microsoft.Dynamics365.UIAutomation.Api.UCI/DTO/AppElementReference.cs index 12daf8ed..dea41477 100644 --- a/Microsoft.Dynamics365.UIAutomation.Api.UCI/DTO/AppElementReference.cs +++ b/Microsoft.Dynamics365.UIAutomation.Api.UCI/DTO/AppElementReference.cs @@ -75,6 +75,8 @@ public static class Entity public static string TextFieldLookup = "Entity_TextFieldLookup"; public static string TextFieldLookupMenu = "Entity_TextFieldLookupMenu"; public static string LookupFieldDeleteExistingValue = "Entity_LookupFieldDeleteExistingValue"; + public static string LookupFieldNoRecordsText = "Entity_LookupFieldNoRecordsText"; + public static string LookupFieldResultList = "Entity_LookupFieldResultList"; public static string LookupFieldHoverExistingValue = "Entity_LookupFieldHoverExistingValue"; public static string LookupResultsDropdown = "Entity_LookupResultsDropdown"; public static string TextFieldLookupFieldContainer = "Entity_TextFieldLookupFieldContainer"; @@ -291,6 +293,8 @@ public static class AppElements { "Entity_TextFieldLookup", "//*[contains(@id, \'systemuserview_id.fieldControl-LookupResultsDropdown')]" }, { "Entity_TextFieldLookupMenu", "//div[contains(@data-id, '[NAME].fieldControl-LookupResultsDropdown_[NAME]') and contains(@data-id,'tabContainer')]" }, { "Entity_LookupFieldDeleteExistingValue", "//*[contains(@data-id, \'[NAME].fieldControl-LookupResultsDropdown_[NAME]_selected_tag_delete')]" }, + { "Entity_LookupFieldNoRecordsText", "//*[@data-id=\'[NAME].fieldControl-LookupResultsDropdown_[NAME]_No_Records_Text']" }, + { "Entity_LookupFieldResultList", "//*[@data-id=\'[NAME].fieldControl-LookupResultsDropdown_[NAME]_tab']" }, { "Entity_LookupFieldHoverExistingValue", "//*[contains(@data-id, \'[NAME].fieldControl-LookupResultsDropdown_[NAME]_SelectedRecordList')]" }, { "Entity_TextFieldLookupFieldContainer", "//*[contains(@data-id, '[NAME].fieldControl-Lookup_[NAME]')]" }, { "Entity_RecordSetNavigatorOpen", "//button[contains(@data-lp-id, 'recordset-navigator')]" }, diff --git a/Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs b/Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs index 26602ff8..7d4eb9cb 100644 --- a/Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs +++ b/Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs @@ -3,6 +3,7 @@ using Microsoft.Dynamics365.UIAutomation.Browser; using OpenQA.Selenium; +using OpenQA.Selenium.Support.UI; using System; using System.Collections.Generic; using System.Collections.Specialized; @@ -1627,15 +1628,19 @@ internal BrowserCommandResult SetValue(LookupItem control, int index = 0) { return this.Execute(GetOptions($"Set Lookup Value: {control.Name}"), driver => { + driver.WaitForTransaction(5); + var fieldContainer = driver.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.Entity.TextFieldLookupFieldContainer].Replace("[NAME]", control.Name))); if (fieldContainer.FindElements(By.TagName("input")).Count == 0) { var existingLookupValue = fieldContainer.FindElement(By.XPath(AppElements.Xpath[AppReference.Entity.LookupFieldHoverExistingValue].Replace("[NAME]", control.Name))); existingLookupValue.Hover(driver); + Thread.Sleep(500); var deleteExistingLookupValue = fieldContainer.FindElement(By.XPath(AppElements.Xpath[AppReference.Entity.LookupFieldDeleteExistingValue].Replace("[NAME]", control.Name))); deleteExistingLookupValue.Click(); + Thread.Sleep(500); } fieldContainer = driver.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.Entity.TextFieldLookupFieldContainer].Replace("[NAME]", control.Name))); @@ -1653,7 +1658,11 @@ internal BrowserCommandResult SetValue(LookupItem control, int index = 0) if (control.Value != null && control.Value != "") { - var flyoutDialog = driver.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.Entity.TextFieldLookupMenu].Replace("[NAME]", control.Name))); + var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); + wait.Until(d => d.FindElement(By.XPath(AppElements.Xpath[AppReference.Entity.LookupFieldNoRecordsText].Replace("[NAME]", control.Name) + "|" + + AppElements.Xpath[AppReference.Entity.LookupFieldResultList].Replace("[NAME]", control.Name)))); + + var flyoutDialog = driver.FindElement(By.XPath(AppElements.Xpath[AppReference.Entity.TextFieldLookupMenu].Replace("[NAME]", control.Name))); var dialogItems = OpenDialog(flyoutDialog).Value; if (dialogItems.Count <= 0)