/// <summary> /// Click on the element /// </summary> public virtual void Click() { if (IsDisabled) { Highlight(); throw new WebControlException(Driver, "Control is disabled.", this); } if (!Exists) { throw new WebControlException(Driver, "Control does not exist.", this); } try { RawElement.Click(); } catch (Exception ex) { if (ex.Message.Contains("is not clickable at point") && ex.Message.Contains("Other element would receive the click")) { //LOG: The element could not be clicked as there is another element which would receive the click ParentRawElement.Click(); } else { Highlight(); throw new WebControlException(Driver, ex, "Control could not be clicked on", this); } } }
public override void Clear() { try { if (_useExtendedClear) { RawElement.SendKeys(Keys.Control + "a"); RawElement.SendKeys(Keys.Delete); if (Value.HasValue()) { base.Clear(); } Value.Should().BeEmpty("Control was not cleared"); } else { base.Clear(); } } catch (Exception ex) { Highlight(); throw new WebControlException(Driver, ex, "Control could not be cleared.", this); } }
public void WaitForTableLoadComplete(bool expectingRows = false) { RawElement.WaitUntilElementVisible(Driver); _loadingSpinner.WaitClickTillElementGoesInvisible(); if (expectingRows) { GetBodyControl <WebControl>(1, 1, getContentWithinTDelement: true).WaitUntilElementVisible(errorMessage: "Table expecting atleast one row to be rendered"); } }
internal bool Serialise(XmlWriter writer, bool serializeCollectionKey) { if (RawElement != null) { RawElement.WriteTo(writer); return(true); } return(SerializeElement(writer, serializeCollectionKey)); }
public int GetColumnPosition(string columnname) { ColumnNames.ContainsIgnoreCase(columnname).Should().BeTrue($"The column name specified [{columnname}] does not exist in the Grid"); return(RawElement.FindElements(By.CssSelector("thead>tr>th")).Union(RawElement.FindElements(By.CssSelector("tbody>tr>th"))) .Select(x => x.Text) .Select((name, index) => new { Name = name, Index = index }) .Where(x => x.Name.Contains(columnname, StringComparison.CurrentCultureIgnoreCase)) .Select(x => x.Index) .FirstOrDefault() + 1); }
/// <summary> /// Applies the content of this Typed Element to an instance /// </summary> /// <param name="target">The target instance to parse the content</param> public void Populate(TypedElement target) { target.Type = Type; if (RawElement == null) { throw new InvalidOperationException("Element content has already been populated"); } using var Reader = RawElement.CreateReader(); Reader.Read(); target.Deserialise(Reader, false); }
/// <summary> /// Waits till the element in the position is removed from the UI /// </summary> /// <param name="waitTimeSec">Maximum amount of time to wait</param> /// <param name="throwExceptionWhenNotFound">Throw exception if the element is not found</param> /// <param name="errorMessage">Error message text when the element is not found</param> public new void WaitForElementInvisible(int waitTimeSec = 0, bool throwExceptionWhenNotFound = true, string errorMessage = "") { if (Total <= 0) { return; } var tempTotal = Total; RawElement.WaitGeneric(driver: Driver, waitTimeSec: waitTimeSec, throwExceptionWhenNotFound: throwExceptionWhenNotFound, errorMessage: errorMessage, () => tempTotal < Total, $"Collection Control failed on element to go invisible {By}", baseControl: this); }
public string Render(string text) { if (string.IsNullOrWhiteSpace(text)) return null; text = NormalizeLineEnds(text); text = text.Replace('\x2012', '-'); text = text.Replace('\x2013', '-'); RawElement rootElement = new RawElement(_parsingContext, new ElementContent(text)); StringWriter writer = new StringWriter(); rootElement.Render(writer); return writer.ToString(); }
/// <summary> /// Waits till the element on the position is available in the UI /// </summary> /// <param name="position">Position of the element as visible in the UI</param> /// <param name="waitTimeSec">Maximum amount of time to wait</param> /// <param name="throwExceptionWhenNotFound">Throw exception if the element is not found</param> /// <param name="errorMessage">Error message text when the element is not found</param> public void WaitForElementVisible(int position, int waitTimeSec = 0, bool throwExceptionWhenNotFound = true, string errorMessage = "") { var currentTotal = Total; (currentTotal == 0 && position > 1).Should() .BeFalse($"The are no UI elements matching and you have requested for {position} to appear"); if (currentTotal == 0) //If there are no such element in the UI then wait for the first one to appear { RawElement.WaitGeneric(driver: Driver, waitTimeSec: waitTimeSec, throwExceptionWhenNotFound: throwExceptionWhenNotFound, errorMessage: errorMessage, () => Total == position, $"Collection Control failed on element to be visible {By}", baseControl: this); } }
/// <summary> /// Sends the text to the element /// </summary> /// <param name="textToSet">Text that needs to be sent</param> public virtual void SendKeys(string textToSet) { if (IsDisabled) { Highlight(); throw new WebControlException(Driver, $"{ToString()} is disabled.", this); } try { RawElement.SendKeys(textToSet); } catch (Exception ex) { Highlight(); throw new WebControlException(Driver, ex, $"Failed to do SendKeys on control {ToString()}.", this); } }
public TableControl( IWebDriver driver, By selector, BaseControl parentControl = null, By loadWaitingSelector = null) : base(driver, selector, parentControl) { { if (WaitUntilElementVisible(waitTimeSec: 2, throwExceptionWhenNotFound: false)) { _totalColumns = RawElement.FindElements(By.CssSelector("thead>tr>th")).Count; } else { RenderedInUi = false; } } LoadWaitingSelector = loadWaitingSelector; }
/// <summary> /// Clear the element content /// </summary> public virtual void Clear() { try { RawElement.Clear(); if (Value.HasValue()) { RawElement.SendKeys(Keys.Control + "a"); RawElement.SendKeys(Keys.Delete); } Value.Should().BeEmpty("Control was not cleared"); } catch (Exception ex) { Highlight(); throw new WebControlException(Driver, ex, "Control could not be cleared.", this); } }
public void Invoke() { ActionHandler.Perform(() => ((InvokePattern)RawElement.GetCurrentPattern(InvokePattern.Pattern)).Invoke()); }
/// <summary> /// Tries to set the focus to the element using Javascript /// </summary> public virtual void SetFocusByJavascript() { var findElementCode = $"(document.evaluate('{RawElement.GetElementXPath(Driver)}', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue).focus();"; Driver.ExecuteJavaScript(findElementCode); }
/// <summary> /// Highlights the element in the UI /// </summary> public virtual void Highlight() => RawElement.Highlight(Driver);
public void Toggle() { ActionHandler.Perform(() => ((TogglePattern)RawElement.GetCurrentPattern(TogglePattern.Pattern)).Toggle()); }
public void Close() { ActionHandler.Perform(() => ((WindowPattern)RawElement.GetCurrentPattern(WindowPattern.Pattern)).Close()); }
public void SetScrollPercent(double horizontalPercent, double verticalPercent) { ActionHandler.Perform(() => ((ScrollPattern)RawElement.GetCurrentPattern(ScrollPattern.Pattern)).SetScrollPercent(horizontalPercent, verticalPercent)); }
public AutomationElement[] GetSelection() { return(ActionHandler.Perform(() => ((SelectionPattern)RawElement.GetCurrentPattern(SelectionPattern.Pattern)).Current.GetSelection())); }
public AutomationElement GetItem(int row, int column) { return(ActionHandler.Perform(() => ((GridPattern)RawElement.GetCurrentPattern(GridPattern.Pattern)).GetItem(row, column))); }
public void Resize(double width, double height) { ActionHandler.Perform(() => ((TransformPattern)RawElement.GetCurrentPattern(TransformPattern.Pattern)).Resize(width, height)); }
public void Move(double x, double y) { ActionHandler.Perform(() => ((TransformPattern)RawElement.GetCurrentPattern(TransformPattern.Pattern)).Move(x, y)); }
/// <summary> /// Return the attribute value of the element /// </summary> /// <param name="attributeName">attribute that needs to be read</param> /// <returns>value of the attribute</returns> public string GetAttribute(string attributeName) => RawElement.GetAttribute(attributeName);
public void Rotate(double degrees) { ActionHandler.Perform(() => ((TransformPattern)RawElement.GetCurrentPattern(TransformPattern.Pattern)).Rotate(degrees)); }
public void Collapse() { ActionHandler.Perform(() => ((ExpandCollapsePattern)RawElement.GetCurrentPattern(ExpandCollapsePattern.Pattern)).Collapse()); }
public AutomationElement[] GetRowHeaders() { return(ActionHandler.Perform(() => ((TablePattern)RawElement.GetCurrentPattern(TablePattern.Pattern)).Current.GetRowHeaders())); }
public void SetDockPosition(DockPosition dockPosition) { ActionHandler.Perform(() => ((DockPattern)RawElement.GetCurrentPattern(DockPattern.Pattern)).SetDockPosition(dockPosition)); }
public void Scroll(ScrollAmount horizontalAmount = 0, ScrollAmount verticalAmount = 0) { ActionHandler.Perform(() => ((ScrollPattern)RawElement.GetCurrentPattern(ScrollPattern.Pattern)).Scroll(horizontalAmount, verticalAmount)); }
public void SetVisualState(WindowVisualState state) { ActionHandler.Perform(() => ((WindowPattern)RawElement.GetCurrentPattern(WindowPattern.Pattern)).SetWindowVisualState(state)); }
public void SetValue(string value) { ActionHandler.Perform(() => ((ValuePattern)RawElement.GetCurrentPattern(ValuePattern.Pattern)).SetValue(value)); }
public bool WaitForInputIdle(int milliseconds) { return(ActionHandler.Perform(() => ((WindowPattern)RawElement.GetCurrentPattern(WindowPattern.Pattern)).WaitForInputIdle(milliseconds))); }