public string CellTextOfRow(string columnName, params object[] keys) { IUIControl row = RowOf(keys); if (row == null) { return(null); } int cellIndex = Headers.IndexOf(columnName); if (cellIndex == -1) { return(null); } By cellByNth = By.CssSelector(string.Format("{0}", "td".CssSelectorOfNthOfType(cellIndex))); IUIControl cell = new UIControl(row, cellByNth); return(cell.Text); }
public bool ClickToShow(UIControl another, Action action = null) { return(Executor.Try(Executor.IsControlVisible(another), action ?? Click)); }
public virtual string Select(string key, bool select = true) { WaitControlReady(); if (ExpandToSelect) { Expand(); } string innerHtml = null; if (WaitOptionAsTextValue) { Executor.Until(() => { innerHtml = this.InnerHTML; if (string.IsNullOrEmpty(innerHtml)) { return(false); } innerHtml = HttpUtility.HtmlDecode(innerHtml)?.Trim(); return(innerHtml.ContainsAll(key)); }, WaitOptionAsTextValueInMills); } if (string.IsNullOrEmpty(innerHtml)) { Logger.W("Failed to get InnerHTML of '{0}'. Select failed.", this); return(""); } else if (!innerHtml.ContainsAll(key)) { Logger.V("InnerHTML:'{0}' doesn't contains '{1}'.", innerHtml, key); } String[] optionTexts = OptionTexts; String[] optionValues = OptionValues; int index = -1; String upperKey = key.ToUpper(); if (optionTexts.Any(s => s.Equals(key))) { index = Array.IndexOf(optionTexts, key); } else if (optionValues.Any(s => s.Equals(key))) { index = Array.IndexOf(optionValues, key); } else if (optionTexts.Any(s => s.ToUpper().Equals(upperKey))) { index = Array.FindIndex(optionTexts, s => s.ToUpper().Equals(upperKey)); } else if (optionValues.Any(s => s.ToUpper().Equals(upperKey))) { index = Array.FindIndex(optionValues, s => s.ToUpper().Equals(upperKey)); } else if (optionTexts.Any(s => s.ToUpper().Contains(upperKey))) { index = Array.FindIndex(optionTexts, s => s.ToUpper().Contains(upperKey)); } else if (optionValues.Any(s => s.ToUpper().Contains(upperKey))) { index = Array.FindIndex(optionValues, s => s.ToUpper().Contains(upperKey)); } if (index == -1) { string errorMessage = string.Format("Failed to select option '{0}' from:\r\n{1}", key, string.Join("\r\n", innerHtml)); Logger.E(errorMessage); throw new NoSuchElementException(errorMessage); } index = index >= 0 ? index : optionValues.Length + index; string oValue = optionValues[index]; By selectedOptionBy = null; if (!string.IsNullOrEmpty(oValue) && Array.IndexOf(optionValues, oValue) == Array.LastIndexOf(optionValues, oValue)) { selectedOptionBy = By.CssSelector(string.Format("option[value='{0}']", oValue)); } else { selectedOptionBy = By.CssSelector("option".CssSelectorOfNthOfType(index)); } Logger.V("{0} => {1}", key, selectedOptionBy); UIControl optionToSelect = new UIControl(this, selectedOptionBy); optionToSelect.Click(() => optionToSelect.GetAttribute("data-selected").Equals("true")); if (ExpandToSelect) { Expand(); } return(optionToSelect.Text); }
public virtual string Select(By optionBy, bool expandToSelect = false) { WaitControlReady(); bool withOnChange = SleepIfOnChangeTriggered && !String.IsNullOrEmpty(this.Element.GetAttribute("onchange")); string selectedText = null; if (!expandToSelect) { UIControl optionControl = new UIControl(this, optionBy); try { selectedText = optionControl.Text; optionControl.Element.Click(); this.element = null; } catch (Exception ex) { Logger.E(ex); return(""); } finally { this.element = null; } } else { try { Size size = this.Element.Size; int yOffset = size.Height / 2; int xOffset = size.Width - yOffset; Actions build = new Actions(Driver); build.MoveToElement(this.Element, xOffset, yOffset).Click().MoveToElement(this.Element, xOffset, size.Height * 3 / 2).Perform(); // System.Threading.Thread.Sleep(WaitMillisAfterExpand); build.MoveToElement(this.Element).Release().Perform(); this.element = null; UIControl optionControl = new UIControl(this, optionBy); selectedText = optionControl.Text; optionControl.Element.Click(); this.element = null; // Thread.Sleep(100); build = new Actions(Driver); build.MoveToElement(this.Element, xOffset, yOffset).Click().Perform(); } catch (Exception ex) { Logger.E(ex); return(""); } finally { this.element = null; } } this.WaitControlReady(1000); if (withOnChange) { Thread.Sleep(SleepAfterOnChange); Logger.V("Sleep {0}ms after select option with text of '{1}'.", SleepAfterOnChange, selectedText); } else { selectedText = this.Text; Logger.V("Text of selected option: {0}", selectedText); } return(selectedText); }