Ejemplo n.º 1
0
        public DataTable GetTableElement(MessengerCommandArguments search, TimeSpan timeout)
        {
            var element = GetElementInFrame(search, timeout);

            if (element == null)
            {
                throw new Exception("Cannot find the HTML element. Try to change the search phrase or \"by\" argument value so that the correct element is found");
            }
            else if (element.TagName != "table")
            {
                throw new Exception($"The element found has the \"{element.TagName}\" tag name. Try to change the search phrase so that the \"table\" element is found instead");
            }

            var dataTable  = new DataTable();
            var trElements = element.FindElements(By.TagName("tr"));

            dataTable = AddColumnNamesFromThElements(dataTable, trElements[0].FindElements(By.TagName("th")));

            foreach (var trElement in trElements)
            {
                var tdElements = trElement.FindElements(By.TagName("td"));
                dataTable = AddColumnsIfThereAreMoreTdElements(dataTable, tdElements.Count);
                dataTable = AddRowToDataTable(dataTable, tdElements);
            }

            return(dataTable);
        }
Ejemplo n.º 2
0
        public void TypeText(string text, MessengerCommandArguments search, TimeSpan timeout)
        {
            var elem = GetElementInFrame(search, timeout);

            elem.SendKeys(text);
            if (string.IsNullOrEmpty(search.IFrameSearch?.Value) == false)
            {
                webDriver.SwitchTo().DefaultContent();
            }
        }
Ejemplo n.º 3
0
        private IWebElement GetElementInFrame(MessengerCommandArguments search, TimeSpan timeout)
        {
            PreCheckCurrentWindowHandle();
            if (!string.IsNullOrEmpty(search.IFrameSearch?.Value))
            {
                webDriver.SwitchTo().Frame(FindElement(search.IFrameSearch.Value, search.IFrameBy.Value, timeout));
            }
            var element = FindElement(search.Search.Value, search.By.Value, timeout);

            return(element);
        }
Ejemplo n.º 4
0
        public string GetTextValue(MessengerCommandArguments search, TimeSpan timeout)
        {
            var element = GetElementInFrame(search, timeout);

            var res = element?.Text ?? string.Empty;

            if (!string.IsNullOrEmpty(search.IFrameSearch?.Value))
            {
                webDriver.SwitchTo().DefaultContent();
            }
            return(res);
        }
Ejemplo n.º 5
0
        public string GetAttributeValue(string attributeName, MessengerCommandArguments search)
        {
            var element = GetElementInFrame(search, search.Timeout.Value);

            var result = element?.GetAttribute(attributeName);

            if (string.IsNullOrEmpty(search.IFrameSearch?.Value) == false)
            {
                webDriver.SwitchTo().DefaultContent();
            }

            return(result ?? string.Empty);
        }
Ejemplo n.º 6
0
        public void Click(MessengerCommandArguments search, TimeSpan timeout, bool waitForNewWindow = false)
        {
            NewPopupWindowHandler popupHandler = new NewPopupWindowHandler(webDriver);
            var     elem    = GetElementInFrame(search, timeout);
            Actions actions = new Actions(webDriver);

            actions.MoveToElement(elem).Click().Build().Perform();
            if (string.IsNullOrEmpty(search.IFrameSearch?.Value) == false)
            {
                webDriver.SwitchTo().DefaultContent();
            }
            popupHandler.Finish(waitForNewWindow, timeout);
        }
Ejemplo n.º 7
0
        public void PressKey(string keyText, MessengerCommandArguments search, TimeSpan timeout)
        {
            NewPopupWindowHandler popupHandler = new NewPopupWindowHandler(webDriver);
            var    elem          = GetElementInFrame(search, timeout);
            string convertedText = typeof(Keys).GetFields().Where(x => x.Name.ToLower() == keyText.ToLower()).FirstOrDefault()?.GetValue(null) as string;

            if (convertedText == null)
            {
                throw new ArgumentException($"Wrong key argument '{keyText}' specified. Please use keys allowed by selenium library.");
            }
            elem.SendKeys(convertedText);
            if (string.IsNullOrEmpty(search.IFrameSearch?.Value) == false)
            {
                webDriver.SwitchTo().DefaultContent();
            }
            popupHandler.Finish();
        }
Ejemplo n.º 8
0
        public void CallFunction(string functionName, object[] arguments, string type, MessengerCommandArguments search, TimeSpan timeout)
        {
            NewPopupWindowHandler popupHandler = new NewPopupWindowHandler(webDriver);

            PreCheckCurrentWindowHandle();
            if (string.IsNullOrEmpty(search.IFrameSearch?.Value) == false)
            {
                webDriver.SwitchTo().Frame(FindElement(search.IFrameSearch.Value, search.IFrameBy.Value, timeout));
            }
            IWebElement element = FindElement(search.Search.Value, search.By.Value, timeout);

            element?.CallFunction(functionName, arguments, type);
            if (string.IsNullOrEmpty(search.IFrameSearch?.Value) == false)
            {
                webDriver.SwitchTo().DefaultContent();
            }
            popupHandler.Finish();
        }
Ejemplo n.º 9
0
 public string GetOuterHtml(MessengerCommandArguments search)
 {
     return(GetAttributeValue("outerHTML", search));
 }
Ejemplo n.º 10
0
        public void SetAttributeValue(string attributeName, string attributeValue, AttributeOperationType setAttributeType, MessengerCommandArguments search, TimeSpan timeout)
        {
            var element = GetElementInFrame(search, timeout);

            if (element != null)
            {
                if (IsAttributeOprtationType(element, attributeName, setAttributeType))
                {
                    element.SetAttribute(attributeName, attributeValue);
                }
                else
                {
                    element.SetProperty(attributeName, attributeValue);
                }
            }
            if (string.IsNullOrEmpty(search.IFrameSearch?.Value) == false)
            {
                webDriver.SwitchTo().DefaultContent();
            }
        }