/// <summary> /// Clears the value of a DateTime field on a QuickCreate form. /// </summary> /// <param name="date">DateTime value.</param> /// <example> xrmBrowser.QuickCreate.ClearValue(new DateTime {Name = "birthdate"}));</example> public BrowserCommandResult <bool> ClearValue(DateTimeControl date) { return(this.Execute(GetOptions($"Clear QuickCreate DateTime Field: {date.Name}"), driver => { if (driver.HasElement(By.XPath(Elements.Xpath[Reference.Entity.DateFieldContainer].Replace("[NAME]", date.Name.ToLower())))) { var fieldElement = driver.WaitUntilAvailable(By.XPath(Elements.Xpath[Reference.Entity.DateFieldContainer].Replace("[NAME]", date.Name.ToLower()))); // Check whether the DateTime field has an existing value if (fieldElement.GetAttribute("title") != "Select to enter data") { fieldElement.Click(true); var fieldInput = driver.WaitUntilAvailable(By.XPath(Elements.Xpath[Reference.Entity.DateFieldInput].Replace("[NAME]", date.Name.ToLower()))); // Clear any existing values fieldInput.Clear(); fieldElement.Click(true); fieldElement.SendKeys(Keys.Enter); } } else { throw new InvalidOperationException($"Unable to locate DateTime field '{date.Name}' on the QuickCreate form. Please verify the DateTime field exists and try again."); } return true; })); }
/// <summary> /// Sets the value of a Date Field on a QuickCreate form. /// </summary> /// <param name="date">DateTimecontrol Name and Value.</param> public new BrowserCommandResult <bool> SetValue(DateTimeControl date) { return(this.Execute(GetOptions($"Set QuickCreate DateTime Value: {date.Name}"), driver => { if (driver.HasElement(By.Id(date.Name))) { var fieldElement = driver.ClickWhenAvailable(By.Id(date.Name)); //Check to see if focus is on field already if (fieldElement.FindElement(By.ClassName(Elements.CssClass[Reference.SetValue.EditClass])) != null) { fieldElement.FindElement(By.ClassName(Elements.CssClass[Reference.SetValue.EditClass])).Click(); } else { fieldElement.FindElement(By.ClassName(Elements.CssClass[Reference.SetValue.ValueClass])).Click(); } var input = fieldElement.FindElement(By.TagName("input")); if (input.GetAttribute("value").Length > 0) { input.Clear(); fieldElement.Click(); input.SendKeys(date.Value.ToShortDateString()); input.SendKeys(Keys.Enter); input.SendKeys(Keys.Tab); } else { fieldElement.Click(); input.SendKeys(date.Value.ToShortDateString()); input.SendKeys(Keys.Enter); input.SendKeys(Keys.Tab); } } else { throw new InvalidOperationException($"Unable to locate DateTime field '{date.Name}' on the QuickCreate form. Please verify the DateTime field exists and try again."); } return true; })); }
/// <summary> /// Gets the value of a DateTime field on a QuickCreate form. /// </summary> /// <param name="date">DateTime value.</param> /// <example> xrmBrowser.QuickCreate.GetValue(new DateTime {Name = "birthdate"));</example> public BrowserCommandResult <string> GetValue(DateTimeControl date) { return(this.Execute(GetOptions($"Get QuickCreate DateTime Value: {date.Name}"), driver => { string dateValue = ""; if (driver.HasElement(By.XPath(Elements.Xpath[Reference.Entity.DateFieldContainer].Replace("[NAME]", date.Name.ToLower())))) { var fieldElement = driver.WaitUntilAvailable(By.XPath(Elements.Xpath[Reference.Entity.DateFieldContainer].Replace("[NAME]", date.Name.ToLower()))); // Check whether the DateTime field has an existing value if (fieldElement.FindElements(By.TagName("label")).Count > 0) { var label = fieldElement.FindElement(By.TagName("label")); dateValue = label.Text; } } else { throw new InvalidOperationException($"Unable to locate DateTime field '{date.Name}' on the QuickCreate form. Please verify the DateTime field exists and try again."); } return dateValue; })); }