Example #1
0
        /// <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);
            }
        }
Example #3
0
        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));
        }
Example #5
0
        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);
        }
Example #8
0
        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);
            }
        }
Example #10
0
        /// <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);
            }
        }
Example #11
0
        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;
        }
Example #12
0
        /// <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);
            }
        }
Example #13
0
 public void Invoke()
 {
     ActionHandler.Perform(() => ((InvokePattern)RawElement.GetCurrentPattern(InvokePattern.Pattern)).Invoke());
 }
Example #14
0
        /// <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);
        }
Example #15
0
 /// <summary>
 /// Highlights the element in the UI
 /// </summary>
 public virtual void Highlight() => RawElement.Highlight(Driver);
Example #16
0
 public void Toggle()
 {
     ActionHandler.Perform(() => ((TogglePattern)RawElement.GetCurrentPattern(TogglePattern.Pattern)).Toggle());
 }
Example #17
0
 public void Close()
 {
     ActionHandler.Perform(() => ((WindowPattern)RawElement.GetCurrentPattern(WindowPattern.Pattern)).Close());
 }
Example #18
0
 public void SetScrollPercent(double horizontalPercent, double verticalPercent)
 {
     ActionHandler.Perform(() => ((ScrollPattern)RawElement.GetCurrentPattern(ScrollPattern.Pattern)).SetScrollPercent(horizontalPercent, verticalPercent));
 }
Example #19
0
 public AutomationElement[] GetSelection()
 {
     return(ActionHandler.Perform(() => ((SelectionPattern)RawElement.GetCurrentPattern(SelectionPattern.Pattern)).Current.GetSelection()));
 }
Example #20
0
 public AutomationElement GetItem(int row, int column)
 {
     return(ActionHandler.Perform(() => ((GridPattern)RawElement.GetCurrentPattern(GridPattern.Pattern)).GetItem(row, column)));
 }
Example #21
0
 public void Resize(double width, double height)
 {
     ActionHandler.Perform(() => ((TransformPattern)RawElement.GetCurrentPattern(TransformPattern.Pattern)).Resize(width, height));
 }
Example #22
0
 public void Move(double x, double y)
 {
     ActionHandler.Perform(() => ((TransformPattern)RawElement.GetCurrentPattern(TransformPattern.Pattern)).Move(x, y));
 }
Example #23
0
 /// <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);
Example #24
0
 public void Rotate(double degrees)
 {
     ActionHandler.Perform(() => ((TransformPattern)RawElement.GetCurrentPattern(TransformPattern.Pattern)).Rotate(degrees));
 }
Example #25
0
 public void Collapse()
 {
     ActionHandler.Perform(() => ((ExpandCollapsePattern)RawElement.GetCurrentPattern(ExpandCollapsePattern.Pattern)).Collapse());
 }
Example #26
0
 public AutomationElement[] GetRowHeaders()
 {
     return(ActionHandler.Perform(() => ((TablePattern)RawElement.GetCurrentPattern(TablePattern.Pattern)).Current.GetRowHeaders()));
 }
Example #27
0
 public void SetDockPosition(DockPosition dockPosition)
 {
     ActionHandler.Perform(() => ((DockPattern)RawElement.GetCurrentPattern(DockPattern.Pattern)).SetDockPosition(dockPosition));
 }
Example #28
0
 public void Scroll(ScrollAmount horizontalAmount = 0, ScrollAmount verticalAmount = 0)
 {
     ActionHandler.Perform(() => ((ScrollPattern)RawElement.GetCurrentPattern(ScrollPattern.Pattern)).Scroll(horizontalAmount, verticalAmount));
 }
Example #29
0
 public void SetVisualState(WindowVisualState state)
 {
     ActionHandler.Perform(() => ((WindowPattern)RawElement.GetCurrentPattern(WindowPattern.Pattern)).SetWindowVisualState(state));
 }
Example #30
0
 public void SetValue(string value)
 {
     ActionHandler.Perform(() => ((ValuePattern)RawElement.GetCurrentPattern(ValuePattern.Pattern)).SetValue(value));
 }
Example #31
0
 public bool WaitForInputIdle(int milliseconds)
 {
     return(ActionHandler.Perform(() => ((WindowPattern)RawElement.GetCurrentPattern(WindowPattern.Pattern)).WaitForInputIdle(milliseconds)));
 }