Exemplo n.º 1
0
        public DataTable GetTableElement(WhatsappCommandArguments 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);
        }
Exemplo n.º 2
0
        public void TypeText(string text, WhatsappCommandArguments search, TimeSpan timeout)
        {
            var elem = GetElementInFrame(search, timeout);

            elem.SendKeys(text);
            if (string.IsNullOrEmpty(search.IFrameSearch?.Value) == false)
            {
                webDriver.SwitchTo().DefaultContent();
            }
        }
Exemplo n.º 3
0
        private IWebElement GetElementInFrame(WhatsappCommandArguments 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);
        }
Exemplo n.º 4
0
        public string GetTextValue(WhatsappCommandArguments 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);
        }
Exemplo n.º 5
0
        public string GetAttributeValue(string attributeName, WhatsappCommandArguments 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);
        }
Exemplo n.º 6
0
        public void Click(WhatsappCommandArguments 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);
        }
Exemplo n.º 7
0
        public void PressKey(string keyText, WhatsappCommandArguments 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();
        }
Exemplo n.º 8
0
        public void CallFunction(string functionName, object[] arguments, string type, WhatsappCommandArguments 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();
        }
Exemplo n.º 9
0
 public string GetOuterHtml(WhatsappCommandArguments search)
 {
     return(GetAttributeValue("outerHTML", search));
 }
Exemplo n.º 10
0
        public void SetAttributeValue(string attributeName, string attributeValue, AttributeOperationType setAttributeType, WhatsappCommandArguments 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();
            }
        }