Example #1
0
        public override void RunCommand(object sender)
        {
            var engine = (AutomationEngineInstance)sender;

            //get variablized input
            var variableInput = v_InputValue.ConvertUserVariableToString(engine);
            var passphrase    = v_PassPhrase.ConvertUserVariableToString(engine);

            string resultData = "";

            if (v_EncryptionType.ConvertUserVariableToString(engine) == "Encrypt")
            {
                //encrypt data
                resultData = EncryptionServices.EncryptString(variableInput, passphrase);
            }
            else if (v_EncryptionType.ConvertUserVariableToString(engine) == "Decrypt")
            {
                //encrypt data
                resultData = EncryptionServices.DecryptString(variableInput, passphrase);
            }
            else
            {
                throw new NotImplementedException($"Encryption Service Requested '{v_EncryptionType.ConvertUserVariableToString(engine)}' has not been implemented");
            }

            resultData.StoreInUserVariable(engine, v_OutputUserVariableName);
        }
        public override void RunCommand(object sender)
        {
            var engine = (AutomationEngineInstance)sender;

            if (v_WindowName != "Current Window")
            {
                ActivateWindowCommand activateWindow = new ActivateWindowCommand
                {
                    v_WindowName = v_WindowName
                };
                activateWindow.RunCommand(sender);
            }

            string textToSend = v_TextToSend.ConvertUserVariableToString(engine);

            if (v_EncryptionOption == "Encrypted")
            {
                textToSend = EncryptionServices.DecryptString(textToSend, "TASKT");
            }

            if (textToSend == "{WIN_KEY}")
            {
                User32Functions.KeyDown(System.Windows.Forms.Keys.LWin);
                User32Functions.KeyUp(System.Windows.Forms.Keys.LWin);
            }
            else if (textToSend.Contains("{WIN_KEY+"))
            {
                User32Functions.KeyDown(System.Windows.Forms.Keys.LWin);
                var remainingText = textToSend.Replace("{WIN_KEY+", "").Replace("}", "");

                foreach (var c in remainingText)
                {
                    System.Windows.Forms.Keys key = (System.Windows.Forms.Keys)Enum.Parse(typeof(System.Windows.Forms.Keys), c.ToString());
                    User32Functions.KeyDown(key);
                }

                User32Functions.KeyUp(System.Windows.Forms.Keys.LWin);

                foreach (var c in remainingText)
                {
                    System.Windows.Forms.Keys key = (System.Windows.Forms.Keys)Enum.Parse(typeof(System.Windows.Forms.Keys), c.ToString());
                    User32Functions.KeyUp(key);
                }
            }
            else
            {
                System.Windows.Forms.SendKeys.SendWait(textToSend);
            }



            System.Threading.Thread.Sleep(500);
        }
Example #3
0
        private OleDbConnection CreateConnection(object sender)
        {
            var engine         = (AutomationEngineInstance)sender;
            var connection     = v_ConnectionString.ConvertUserVariableToString(engine);
            var connectionPass = v_ConnectionStringPassword.ConvertUserVariableToString(engine);

            if (connectionPass.StartsWith("!"))
            {
                connectionPass = connectionPass.Substring(1);
                connectionPass = EncryptionServices.DecryptString(connectionPass, "openbots-database-automation");
            }
            connection = connection.Replace("#pwd", connectionPass);

            return(new OleDbConnection(connection));
        }
Example #4
0
        private OleDbConnection CreateConnection(object sender)
        {
            var connection     = v_ConnectionString.ConvertToUserVariable(sender);
            var connectionPass = v_ConnectionStringPassword.ConvertToUserVariable(sender);

            if (connectionPass.StartsWith("!"))
            {
                connectionPass = connectionPass.Substring(1);
                connectionPass = EncryptionServices.DecryptString(connectionPass, "taskt-database-automation");
            }

            connection = connection.Replace("#pwd", connectionPass);

            return(new OleDbConnection(connection));
        }
Example #5
0
        public override void RunCommand(object sender)
        {
            var engine             = (IAutomationEngineInstance)sender;
            var variableWindowName = v_WindowName.ConvertUserVariableToString(engine);

            if (variableWindowName != "Current Window")
            {
                User32Functions.ActivateWindow(variableWindowName);
            }

            string textToSend = v_TextToSend.ConvertUserVariableToString(engine);

            if (v_EncryptionOption == "Encrypted")
            {
                textToSend = EncryptionServices.DecryptString(textToSend, "OPENBOTS");
            }

            if (textToSend == "{WIN_KEY}")
            {
                User32Functions.KeyDown(Keys.LWin);
                User32Functions.KeyUp(Keys.LWin);
            }
            else if (textToSend.Contains("{WIN_KEY+"))
            {
                User32Functions.KeyDown(Keys.LWin);
                var remainingText = textToSend.Replace("{WIN_KEY+", "").Replace("}", "");

                foreach (var c in remainingText)
                {
                    Keys key = (Keys)Enum.Parse(typeof(Keys), c.ToString());
                    User32Functions.KeyDown(key);
                }
                User32Functions.KeyUp(Keys.LWin);

                foreach (var c in remainingText)
                {
                    Keys key = (Keys)Enum.Parse(typeof(Keys), c.ToString());
                    User32Functions.KeyUp(key);
                }
            }
            else
            {
                SendKeys.SendWait(textToSend);
            }

            Thread.Sleep(500);
        }
Example #6
0
        public override void RunCommand(object sender)
        {
            var engine = (IAutomationEngineInstance)sender;

            var variableInput = v_InputValue.ConvertUserVariableToString(engine);
            var passphrase    = v_PassPhrase.ConvertUserVariableToString(engine);

            string resultData = "";

            if (v_EncryptionType == "Encrypt")
            {
                resultData = EncryptionServices.EncryptString(variableInput, passphrase);
            }
            else if (v_EncryptionType == "Decrypt")
            {
                resultData = EncryptionServices.DecryptString(variableInput, passphrase);
            }

            resultData.StoreInUserVariable(engine, v_OutputUserVariableName, nameof(v_OutputUserVariableName), this);
        }
        public async override Tasks.Task RunCommand(object sender)
        {
            var engine = (IAutomationEngineInstance)sender;

            var variableInput = (string)await v_InputValue.EvaluateCode(engine);

            var passphrase = (string)await v_PassPhrase.EvaluateCode(engine);

            string resultData = "";

            if (v_EncryptionType == "Encrypt")
            {
                resultData = EncryptionServices.EncryptString(variableInput, passphrase);
            }
            else if (v_EncryptionType == "Decrypt")
            {
                resultData = EncryptionServices.DecryptString(variableInput, passphrase);
            }

            resultData.SetVariableValue(engine, v_OutputUserVariableName);
        }
        public override void RunCommand(object sender)
        {
            var engine = (AutomationEngineInstance)sender;
            //create variable window name
            var variableWindowName = v_WindowName.ConvertUserVariableToString(engine);

            if (variableWindowName == "Current Window")
            {
                variableWindowName = User32Functions.GetActiveWindowTitle();
            }

            dynamic requiredHandle = null;

            if (v_AutomationType != "Wait For Element To Exist")
            {
                requiredHandle = SearchForGUIElement(sender, variableWindowName);
            }

            switch (v_AutomationType)
            {
            //determine element click type
            case "Click Element":
                //if handle was not found
                if (requiredHandle == null)
                {
                    throw new Exception("Element was not found in window '" + variableWindowName + "'");
                }
                //create search params
                var clickType = (from rw in v_UIAActionParameters.AsEnumerable()
                                 where rw.Field <string>("Parameter Name") == "Click Type"
                                 select rw.Field <string>("Parameter Value")).FirstOrDefault();

                //get x adjust
                var xAdjust = (from rw in v_UIAActionParameters.AsEnumerable()
                               where rw.Field <string>("Parameter Name") == "X Adjustment"
                               select rw.Field <string>("Parameter Value")).FirstOrDefault();

                //get y adjust
                var yAdjust = (from rw in v_UIAActionParameters.AsEnumerable()
                               where rw.Field <string>("Parameter Name") == "Y Adjustment"
                               select rw.Field <string>("Parameter Value")).FirstOrDefault();

                //convert potential variable
                var xAdjustVariable = xAdjust.ConvertUserVariableToString(engine);
                var yAdjustVariable = yAdjust.ConvertUserVariableToString(engine);

                //parse to int
                var xAdjustInt = int.Parse(xAdjustVariable);
                var yAdjustInt = int.Parse(yAdjustVariable);

                //get clickable point
                var newPoint = requiredHandle.GetClickablePoint();

                //send mousemove command
                var newMouseMove = new SendMouseMoveCommand
                {
                    v_XMousePosition = (newPoint.X + xAdjustInt).ToString(),
                    v_YMousePosition = (newPoint.Y + yAdjustInt).ToString(),
                    v_MouseClick     = clickType
                };

                //run commands
                newMouseMove.RunCommand(sender);
                break;

            case "Set Text":
                string textToSet = (from rw in v_UIAActionParameters.AsEnumerable()
                                    where rw.Field <string>("Parameter Name") == "Text To Set"
                                    select rw.Field <string>("Parameter Value")).FirstOrDefault();


                string clearElement = (from rw in v_UIAActionParameters.AsEnumerable()
                                       where rw.Field <string>("Parameter Name") == "Clear Element Before Setting Text"
                                       select rw.Field <string>("Parameter Value")).FirstOrDefault();

                string encryptedData = (from rw in v_UIAActionParameters.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Encrypted Text"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault();
                if (clearElement == null)
                {
                    clearElement = "No";
                }
                if (encryptedData == "Encrypted")
                {
                    textToSet = EncryptionServices.DecryptString(textToSet, "TASKT");
                }
                textToSet = textToSet.ConvertUserVariableToString(engine);

                if (requiredHandle.Current.IsEnabled && requiredHandle.Current.IsKeyboardFocusable)
                {
                    object valuePattern = null;
                    if (!requiredHandle.TryGetCurrentPattern(ValuePattern.Pattern, out valuePattern))
                    {
                        //The control does not support ValuePattern Using keyboard input

                        // Set focus for input functionality and begin.
                        requiredHandle.SetFocus();

                        // Pause before sending keyboard input.
                        Thread.Sleep(100);

                        if (clearElement.ToLower() == "yes")
                        {
                            // Delete existing content in the control and insert new content.
                            SendKeys.SendWait("^{HOME}");       // Move to start of control
                            SendKeys.SendWait("^+{END}");       // Select everything
                            SendKeys.SendWait("{DEL}");         // Delete selection
                        }
                        SendKeys.SendWait(textToSet);
                    }
                    else
                    {
                        if (clearElement.ToLower() == "no")
                        {
                            string currentText;
                            object tPattern = null;
                            if (requiredHandle.TryGetCurrentPattern(TextPattern.Pattern, out tPattern))
                            {
                                var textPattern = (TextPattern)tPattern;
                                currentText = textPattern.DocumentRange.GetText(-1).TrimEnd('\r').ToString();     // often there is an extra '\r' hanging off the end.
                            }
                            else
                            {
                                currentText = requiredHandle.Current.Name.ToString();
                            }
                            textToSet = currentText + textToSet;
                        }
                        requiredHandle.SetFocus();
                        ((ValuePattern)valuePattern).SetValue(textToSet);
                    }
                }
                break;

            case "Set Secure Text":
                string secureString = (from rw in v_UIAActionParameters.AsEnumerable()
                                       where rw.Field <string>("Parameter Name") == "Secure String Variable"
                                       select rw.Field <string>("Parameter Value")).FirstOrDefault();

                string _clearElement = (from rw in v_UIAActionParameters.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Clear Element Before Setting Text"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault();

                var secureStrVariable = secureString.ConvertUserVariableToObject(engine);

                if (secureStrVariable is SecureString)
                {
                    secureString = ((SecureString)secureStrVariable).ConvertSecureStringToString();
                }
                else
                {
                    throw new ArgumentException("Provided Argument is not a 'Secure String'");
                }

                if (_clearElement == null)
                {
                    _clearElement = "No";
                }

                if (requiredHandle.Current.IsEnabled && requiredHandle.Current.IsKeyboardFocusable)
                {
                    object valuePattern = null;
                    if (!requiredHandle.TryGetCurrentPattern(ValuePattern.Pattern, out valuePattern))
                    {
                        //The control does not support ValuePattern Using keyboard input

                        // Set focus for input functionality and begin.
                        requiredHandle.SetFocus();

                        // Pause before sending keyboard input.
                        Thread.Sleep(100);

                        if (_clearElement.ToLower() == "yes")
                        {
                            // Delete existing content in the control and insert new content.
                            SendKeys.SendWait("^{HOME}");       // Move to start of control
                            SendKeys.SendWait("^+{END}");       // Select everything
                            SendKeys.SendWait("{DEL}");         // Delete selection
                        }
                        SendKeys.SendWait(secureString);
                    }
                    else
                    {
                        if (_clearElement.ToLower() == "no")
                        {
                            string currentText;
                            object tPattern = null;
                            if (requiredHandle.TryGetCurrentPattern(TextPattern.Pattern, out tPattern))
                            {
                                var textPattern = (TextPattern)tPattern;
                                currentText = textPattern.DocumentRange.GetText(-1).TrimEnd('\r').ToString();     // often there is an extra '\r' hanging off the end.
                            }
                            else
                            {
                                currentText = requiredHandle.Current.Name.ToString();
                            }
                            secureString = currentText + secureString;
                        }
                        requiredHandle.SetFocus();
                        ((ValuePattern)valuePattern).SetValue(secureString);
                    }
                }
                break;

            case "Clear Element":
                if (requiredHandle.Current.IsEnabled && requiredHandle.Current.IsKeyboardFocusable)
                {
                    object valuePattern = null;
                    if (!requiredHandle.TryGetCurrentPattern(ValuePattern.Pattern, out valuePattern))
                    {
                        //The control does not support ValuePattern Using keyboard input

                        // Set focus for input functionality and begin.
                        requiredHandle.SetFocus();

                        // Pause before sending keyboard input.
                        Thread.Sleep(100);

                        // Delete existing content in the control and insert new content.
                        SendKeys.SendWait("^{HOME}");       // Move to start of control
                        SendKeys.SendWait("^+{END}");       // Select everything
                        SendKeys.SendWait("{DEL}");         // Delete selection
                    }
                    else
                    {
                        requiredHandle.SetFocus();
                        ((ValuePattern)valuePattern).SetValue("");
                    }
                }
                break;

            case "Get Text":
            //if element exists type
            case "Check If Element Exists":
                //apply to variable
                var applyToVariable = (from rw in v_UIAActionParameters.AsEnumerable()
                                       where rw.Field <string>("Parameter Name") == "Apply To Variable"
                                       select rw.Field <string>("Parameter Value")).FirstOrDefault();

                //declare search result
                string searchResult = "";
                if (v_AutomationType == "Get Text")
                {
                    //string currentText;
                    object tPattern = null;
                    if (requiredHandle.TryGetCurrentPattern(TextPattern.Pattern, out tPattern))
                    {
                        var textPattern = (TextPattern)tPattern;
                        searchResult = textPattern.DocumentRange.GetText(-1).TrimEnd('\r').ToString();     // often there is an extra '\r' hanging off the end.
                    }
                    else
                    {
                        searchResult = requiredHandle.Current.Name.ToString();
                    }
                }

                else if (v_AutomationType == "Check If Element Exists")
                {
                    //determine search result
                    if (requiredHandle == null)
                    {
                        searchResult = "False";
                    }
                    else
                    {
                        searchResult = "True";
                    }
                }
                //store data
                searchResult.StoreInUserVariable(engine, applyToVariable);
                break;

            case "Wait For Element To Exist":
                var timeoutText = (from rw in v_UIAActionParameters.AsEnumerable()
                                   where rw.Field <string>("Parameter Name") == "Timeout (Seconds)"
                                   select rw.Field <string>("Parameter Value")).FirstOrDefault();

                timeoutText = timeoutText.ConvertUserVariableToString(engine);

                int timeOut = Convert.ToInt32(timeoutText);

                var timeToEnd = DateTime.Now.AddSeconds(timeOut);
                while (timeToEnd >= DateTime.Now)
                {
                    try
                    {
                        requiredHandle = SearchForGUIElement(sender, variableWindowName);
                        break;
                    }
                    catch (Exception)
                    {
                        engine.ReportProgress("Element Not Yet Found... " + (timeToEnd - DateTime.Now).Seconds + "s remain");
                        Thread.Sleep(1000);
                    }
                }
                break;

            case "Get Value From Element":
                if (requiredHandle == null)
                {
                    throw new Exception("Element was not found in window '" + variableWindowName + "'");
                }
                //get value from property
                var propertyName = (from rw in v_UIAActionParameters.AsEnumerable()
                                    where rw.Field <string>("Parameter Name") == "Get Value From"
                                    select rw.Field <string>("Parameter Value")).FirstOrDefault();

                //apply to variable
                var applyToVariable2 = (from rw in v_UIAActionParameters.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Apply To Variable"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault();

                //get required value
                var requiredValue = requiredHandle.Current.GetType().GetRuntimeProperty(propertyName)?.GetValue(requiredHandle.Current).ToString();

                //store into variable
                ((object)requiredValue).StoreInUserVariable(engine, applyToVariable2);
                break;

            default:
                throw new NotImplementedException("Automation type '" + v_AutomationType + "' not supported.");
            }
        }
        public override void RunCommand(object sender)
        {
            var  engine   = (AutomationEngineInstance)sender;
            bool testMode = TestMode;
            //user image to bitmap
            Bitmap userImage = new Bitmap(Common.Base64ToImage(v_ImageCapture));
            double accuracy;

            try
            {
                accuracy = double.Parse(v_MatchAccuracy.ConvertUserVariableToString(engine));
                if (accuracy > 1 || accuracy < 0)
                {
                    throw new ArgumentOutOfRangeException("Accuracy value is out of range (0-1)");
                }
            }
            catch (Exception)
            {
                throw new InvalidDataException("Accuracy value is invalid");
            }

            if (testMode)
            {
                FindImageElement(userImage, accuracy);
                return;
            }

            dynamic element = null;

            if (v_ImageAction == "Wait For Image To Exist")
            {
                var timeoutText = (from rw in v_ImageActionParameterTable.AsEnumerable()
                                   where rw.Field <string>("Parameter Name") == "Timeout (Seconds)"
                                   select rw.Field <string>("Parameter Value")).FirstOrDefault();

                timeoutText = timeoutText.ConvertUserVariableToString(engine);
                int timeOut   = Convert.ToInt32(timeoutText);
                var timeToEnd = DateTime.Now.AddSeconds(timeOut);

                while (timeToEnd >= DateTime.Now)
                {
                    try
                    {
                        element = FindImageElement(userImage, accuracy);

                        if (element == null)
                        {
                            throw new Exception("Image Element Not Found");
                        }
                        else
                        {
                            break;
                        }
                    }
                    catch (Exception)
                    {
                        engine.ReportProgress("Element Not Yet Found... " + (timeToEnd - DateTime.Now).Seconds + "s remain");
                        Thread.Sleep(1000);
                    }
                }

                if (element == null)
                {
                    throw new Exception("Image Element Not Found");
                }

                return;
            }
            else
            {
                element = FindImageElement(userImage, accuracy);
            }

            try
            {
                string clickPosition;
                int    xAdjust;
                int    yAdjust;
                switch (v_ImageAction)
                {
                case "Click Image":
                    string clickType = (from rw in v_ImageActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Click Type"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault();
                    clickPosition = (from rw in v_ImageActionParameterTable.AsEnumerable()
                                     where rw.Field <string>("Parameter Name") == "Click Position"
                                     select rw.Field <string>("Parameter Value")).FirstOrDefault();
                    xAdjust = Convert.ToInt32((from rw in v_ImageActionParameterTable.AsEnumerable()
                                               where rw.Field <string>("Parameter Name") == "X Adjustment"
                                               select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));
                    yAdjust = Convert.ToInt32((from rw in v_ImageActionParameterTable.AsEnumerable()
                                               where rw.Field <string>("Parameter Name") == "Y Adjustment"
                                               select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));

                    Point clickPositionPoint = GetClickPosition(clickPosition, element);

                    //move mouse to position
                    var mouseX = (clickPositionPoint.X + xAdjust).ToString();
                    var mouseY = (clickPositionPoint.Y + yAdjust).ToString();
                    User32Functions.SendMouseMove(mouseX, mouseY, clickType);
                    break;

                case "Set Text":
                    string textToSet = (from rw in v_ImageActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Text To Set"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine);
                    clickPosition = (from rw in v_ImageActionParameterTable.AsEnumerable()
                                     where rw.Field <string>("Parameter Name") == "Click Position"
                                     select rw.Field <string>("Parameter Value")).FirstOrDefault();
                    xAdjust = Convert.ToInt32((from rw in v_ImageActionParameterTable.AsEnumerable()
                                               where rw.Field <string>("Parameter Name") == "X Adjustment"
                                               select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));
                    yAdjust = Convert.ToInt32((from rw in v_ImageActionParameterTable.AsEnumerable()
                                               where rw.Field <string>("Parameter Name") == "Y Adjustment"
                                               select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));
                    string encryptedData = (from rw in v_ImageActionParameterTable.AsEnumerable()
                                            where rw.Field <string>("Parameter Name") == "Encrypted Text"
                                            select rw.Field <string>("Parameter Value")).FirstOrDefault();

                    if (encryptedData == "Encrypted")
                    {
                        textToSet = EncryptionServices.DecryptString(textToSet, "OPENBOTS");
                    }

                    Point setTextPositionPoint = GetClickPosition(clickPosition, element);

                    //move mouse to position and set text
                    var xPos = (setTextPositionPoint.X + xAdjust).ToString();
                    var yPos = (setTextPositionPoint.Y + yAdjust).ToString();
                    User32Functions.SendMouseMove(xPos, yPos, "Left Click");

                    var simulator = new InputSimulator();
                    simulator.Keyboard.TextEntry(textToSet);
                    Thread.Sleep(100);
                    break;

                case "Set Secure Text":
                    var secureString = (from rw in v_ImageActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Secure String Variable"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault();
                    clickPosition = (from rw in v_ImageActionParameterTable.AsEnumerable()
                                     where rw.Field <string>("Parameter Name") == "Click Position"
                                     select rw.Field <string>("Parameter Value")).FirstOrDefault();
                    xAdjust = Convert.ToInt32((from rw in v_ImageActionParameterTable.AsEnumerable()
                                               where rw.Field <string>("Parameter Name") == "X Adjustment"
                                               select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));
                    yAdjust = Convert.ToInt32((from rw in v_ImageActionParameterTable.AsEnumerable()
                                               where rw.Field <string>("Parameter Name") == "Y Adjustment"
                                               select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));

                    var secureStrVariable = secureString.ConvertUserVariableToObject(engine);

                    if (secureStrVariable is SecureString)
                    {
                        secureString = ((SecureString)secureStrVariable).ConvertSecureStringToString();
                    }
                    else
                    {
                        throw new ArgumentException("Provided Argument is not a 'Secure String'");
                    }

                    Point setSecureTextPositionPoint = GetClickPosition(clickPosition, element);

                    //move mouse to position and set text
                    var xPosition = (setSecureTextPositionPoint.X + xAdjust).ToString();
                    var yPosition = (setSecureTextPositionPoint.Y + yAdjust).ToString();
                    User32Functions.SendMouseMove(xPosition, yPosition, "Left Click");

                    var simulator2 = new InputSimulator();
                    simulator2.Keyboard.TextEntry(secureString);
                    Thread.Sleep(100);
                    break;

                case "Check If Image Exists":
                    var outputVariable = (from rw in v_ImageActionParameterTable.AsEnumerable()
                                          where rw.Field <string>("Parameter Name") == "Output Bool Variable Name"
                                          select rw.Field <string>("Parameter Value")).FirstOrDefault();

                    //remove brackets from variable
                    outputVariable = outputVariable.Replace("{", "").Replace("}", "");

                    if (element != null)
                    {
                        "True".StoreInUserVariable(engine, outputVariable);
                    }
                    else
                    {
                        "False".StoreInUserVariable(engine, outputVariable);
                    }
                    break;

                default:
                    break;
                }
                UIControlsHelper.ShowAllForms();
            }
            catch (Exception ex)
            {
                UIControlsHelper.ShowAllForms();
                if (element == null)
                {
                    throw new Exception("Specified image was not found in window!");
                }
                else
                {
                    throw ex;
                }
            }
        }
Example #10
0
        public override void RunCommand(object sender)
        {
            var engine = (AutomationEngineInstance)sender;
            //convert to user variable -- https://github.com/saucepleez/taskt/issues/66
            var     seleniumSearchParam = v_SeleniumSearchParameter.ConvertUserVariableToString(engine);
            var     browserObject       = v_InstanceName.GetAppInstance(engine);
            var     seleniumInstance    = (IWebDriver)browserObject;
            dynamic element             = null;

            if (v_SeleniumElementAction == "Wait For Element To Exist")
            {
                var timeoutText = (from rw in v_WebActionParameterTable.AsEnumerable()
                                   where rw.Field <string>("Parameter Name") == "Timeout (Seconds)"
                                   select rw.Field <string>("Parameter Value")).FirstOrDefault();

                timeoutText = timeoutText.ConvertUserVariableToString(engine);
                int timeOut   = Convert.ToInt32(timeoutText);
                var timeToEnd = DateTime.Now.AddSeconds(timeOut);

                while (timeToEnd >= DateTime.Now)
                {
                    try
                    {
                        element = FindElement(seleniumInstance, seleniumSearchParam);
                        break;
                    }
                    catch (Exception)
                    {
                        engine.ReportProgress("Element Not Yet Found... " + (timeToEnd - DateTime.Now).Seconds + "s remain");
                        Thread.Sleep(1000);
                    }
                }

                if (element == null)
                {
                    throw new Exception("Element Not Found");
                }

                return;
            }
            else if (seleniumSearchParam != string.Empty)
            {
                element = FindElement(seleniumInstance, seleniumSearchParam);
            }

            switch (v_SeleniumElementAction)
            {
            case "Invoke Click":
                int seleniumWindowHeightY = seleniumInstance.Manage().Window.Size.Height;
                int elementPositionY      = element.Location.Y;
                if (elementPositionY > seleniumWindowHeightY)
                {
                    String scroll          = String.Format("window.scroll(0, {0})", elementPositionY);
                    IJavaScriptExecutor js = browserObject as IJavaScriptExecutor;
                    js.ExecuteScript(scroll);
                }
                element.Click();
                break;

            case "Left Click":
            case "Right Click":
            case "Middle Click":
            case "Double Left Click":
                int userXAdjust = Convert.ToInt32((from rw in v_WebActionParameterTable.AsEnumerable()
                                                   where rw.Field <string>("Parameter Name") == "X Adjustment"
                                                   select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));

                int userYAdjust = Convert.ToInt32((from rw in v_WebActionParameterTable.AsEnumerable()
                                                   where rw.Field <string>("Parameter Name") == "Y Adjustment"
                                                   select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));

                var elementLocation = element.Location;
                SendMouseMoveCommand newMouseMove = new SendMouseMoveCommand();
                var seleniumWindowPosition        = seleniumInstance.Manage().Window.Position;
                newMouseMove.v_XMousePosition = (seleniumWindowPosition.X + elementLocation.X + 30 + userXAdjust).ToString();     // added 30 for offset
                newMouseMove.v_YMousePosition = (seleniumWindowPosition.Y + elementLocation.Y + 130 + userYAdjust).ToString();    //added 130 for offset
                newMouseMove.v_MouseClick     = v_SeleniumElementAction;
                newMouseMove.RunCommand(sender);
                break;

            case "Set Text":
                string textToSet = (from rw in v_WebActionParameterTable.AsEnumerable()
                                    where rw.Field <string>("Parameter Name") == "Text To Set"
                                    select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine);


                string clearElement = (from rw in v_WebActionParameterTable.AsEnumerable()
                                       where rw.Field <string>("Parameter Name") == "Clear Element Before Setting Text"
                                       select rw.Field <string>("Parameter Value")).FirstOrDefault();

                string encryptedData = (from rw in v_WebActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Encrypted Text"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault();

                if (clearElement == null)
                {
                    clearElement = "No";
                }

                if (clearElement.ToLower() == "yes")
                {
                    element.Clear();
                }

                if (encryptedData == "Encrypted")
                {
                    textToSet = EncryptionServices.DecryptString(textToSet, "TASKT");
                }

                string[] potentialKeyPresses = textToSet.Split('{', '}');

                Type        seleniumKeys = typeof(OpenQA.Selenium.Keys);
                FieldInfo[] fields       = seleniumKeys.GetFields(BindingFlags.Static | BindingFlags.Public);

                //check if chunked string contains a key press command like {ENTER}
                foreach (string chunkedString in potentialKeyPresses)
                {
                    if (chunkedString == "")
                    {
                        continue;
                    }

                    if (fields.Any(f => f.Name == chunkedString))
                    {
                        string keyPress = (string)fields.Where(f => f.Name == chunkedString).FirstOrDefault().GetValue(null);
                        element.SendKeys(keyPress);
                    }
                    else
                    {
                        //convert to user variable - https://github.com/saucepleez/taskt/issues/22
                        var convertedChunk = chunkedString.ConvertUserVariableToString(engine);
                        element.SendKeys(convertedChunk);
                    }
                }
                break;

            case "Set Secure Text":
                var secureString = (from rw in v_WebActionParameterTable.AsEnumerable()
                                    where rw.Field <string>("Parameter Name") == "Secure String Variable"
                                    select rw.Field <string>("Parameter Value")).FirstOrDefault();

                string _clearElement = (from rw in v_WebActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Clear Element Before Setting Text"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault();

                var secureStrVariable = secureString.ConvertUserVariableToObject(engine);

                if (secureStrVariable is SecureString)
                {
                    secureString = ((SecureString)secureStrVariable).ConvertSecureStringToString();
                }
                else
                {
                    throw new ArgumentException("Provided Argument is not a 'Secure String'");
                }

                if (_clearElement == null)
                {
                    _clearElement = "No";
                }

                if (_clearElement.ToLower() == "yes")
                {
                    element.Clear();
                }

                string[] _potentialKeyPresses = secureString.Split('{', '}');

                Type        _seleniumKeys = typeof(OpenQA.Selenium.Keys);
                FieldInfo[] _fields       = _seleniumKeys.GetFields(BindingFlags.Static | BindingFlags.Public);

                //check if chunked string contains a key press command like {ENTER}
                foreach (string chunkedString in _potentialKeyPresses)
                {
                    if (chunkedString == "")
                    {
                        continue;
                    }

                    if (_fields.Any(f => f.Name == chunkedString))
                    {
                        string keyPress = (string)_fields.Where(f => f.Name == chunkedString).FirstOrDefault().GetValue(null);
                        element.SendKeys(keyPress);
                    }
                    else
                    {
                        //convert to user variable - https://github.com/saucepleez/taskt/issues/22
                        var convertedChunk = chunkedString.ConvertUserVariableToString(engine);
                        element.SendKeys(convertedChunk);
                    }
                }
                break;

            case "Get Options":
                string applyToVarName = (from rw in v_WebActionParameterTable.AsEnumerable()
                                         where rw.Field <string>("Parameter Name") == "Variable Name"
                                         select rw.Field <string>("Parameter Value")).FirstOrDefault();


                string attribName = (from rw in v_WebActionParameterTable.AsEnumerable()
                                     where rw.Field <string>("Parameter Name") == "Attribute Name"
                                     select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine);

                var optionsItems = new List <string>();
                var ele          = (IWebElement)element;
                var select       = new SelectElement(ele);
                var options      = select.Options;

                foreach (var option in options)
                {
                    var optionValue = option.GetAttribute(attribName);
                    optionsItems.Add(optionValue);
                }

                optionsItems.StoreInUserVariable(engine, applyToVarName);

                break;

            case "Select Option":
                string selectionType = (from rw in v_WebActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Selection Type"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault();

                string selectionParam = (from rw in v_WebActionParameterTable.AsEnumerable()
                                         where rw.Field <string>("Parameter Name") == "Selection Parameter"
                                         select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine);

                seleniumInstance.SwitchTo().ActiveElement();

                var el = (IWebElement)element;
                var selectionElement = new SelectElement(el);

                switch (selectionType)
                {
                case "Select By Index":
                    selectionElement.SelectByIndex(int.Parse(selectionParam));
                    break;

                case "Select By Text":
                    selectionElement.SelectByText(selectionParam);
                    break;

                case "Select By Value":
                    selectionElement.SelectByValue(selectionParam);
                    break;

                case "Deselect By Index":
                    selectionElement.DeselectByIndex(int.Parse(selectionParam));
                    break;

                case "Deselect By Text":
                    selectionElement.DeselectByText(selectionParam);
                    break;

                case "Deselect By Value":
                    selectionElement.DeselectByValue(selectionParam);
                    break;

                case "Deselect All":
                    selectionElement.DeselectAll();
                    break;

                default:
                    throw new NotImplementedException();
                }
                break;

            case "Get Text":
            case "Get Attribute":
            case "Get Count":
                string VariableName = (from rw in v_WebActionParameterTable.AsEnumerable()
                                       where rw.Field <string>("Parameter Name") == "Variable Name"
                                       select rw.Field <string>("Parameter Value")).FirstOrDefault();

                string attributeName = (from rw in v_WebActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Attribute Name"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine);

                string elementValue;
                if (v_SeleniumElementAction == "Get Text")
                {
                    elementValue = element.Text;
                }
                else if (v_SeleniumElementAction == "Get Count")
                {
                    elementValue = "1";
                    if (element is ReadOnlyCollection <IWebElement> )
                    {
                        elementValue = ((ReadOnlyCollection <IWebElement>)element).Count().ToString();
                    }
                }
                else
                {
                    elementValue = element.GetAttribute(attributeName);
                }

                elementValue.StoreInUserVariable(engine, VariableName);
                break;

            case "Get Matching Element(s)":
                var variableName = (from rw in v_WebActionParameterTable.AsEnumerable()
                                    where rw.Field <string>("Parameter Name") == "Variable Name"
                                    select rw.Field <string>("Parameter Value")).FirstOrDefault();

                if (!(element is IWebElement))
                {
                    //create element list
                    List <IWebElement> elementList = new List <IWebElement>();
                    foreach (IWebElement item in element)
                    {
                        elementList.Add(item);
                    }
                    elementList.StoreInUserVariable(engine, variableName);
                }
                else
                {
                    ((IWebElement)element).StoreInUserVariable(engine, variableName);
                }
                break;

            case "Get Table":
                var DTVariableName = (from rw in v_WebActionParameterTable.AsEnumerable()
                                      where rw.Field <string>("Parameter Name") == "Variable Name"
                                      select rw.Field <string>("Parameter Value")).FirstOrDefault();

                // Get HTML (Source) of the Element
                string       tableHTML = element.GetAttribute("innerHTML").ToString();
                HtmlDocument doc       = new HtmlDocument();

                //Load Source (String) as HTML Document
                doc.LoadHtml(tableHTML);

                //Get Header Tags
                var       headers = doc.DocumentNode.SelectNodes("//tr/th");
                DataTable DT      = new DataTable();

                //If headers found
                if (headers != null && headers.Count != 0)
                {
                    // add columns from th (headers)
                    foreach (HtmlNode header in headers)
                    {
                        DT.Columns.Add(Regex.Replace(header.InnerText, @"\t|\n|\r", "").Trim());
                    }
                }
                else
                {
                    var columnsCount = doc.DocumentNode.SelectSingleNode("//tr[1]").ChildNodes.Where(node => node.Name == "td").Count();
                    DT.Columns.AddRange((Enumerable.Range(1, columnsCount).Select(dc => new DataColumn())).ToArray());
                }

                // select rows with td elements and load each row (containing <td> tags) into DataTable
                foreach (var row in doc.DocumentNode.SelectNodes("//tr[td]"))
                {
                    DT.Rows.Add(row.SelectNodes("td").Select(td => Regex.Replace(td.InnerText, @"\t|\n|\r", "").Trim()).ToArray());
                }

                DT.StoreInUserVariable(engine, DTVariableName);
                break;

            case "Clear Element":
                element.Clear();
                break;

            case "Switch to Frame":
                if (seleniumSearchParam == "")
                {
                    seleniumInstance.SwitchTo().DefaultContent();
                }
                else
                {
                    seleniumInstance.SwitchTo().Frame(element);
                }
                break;

            default:
                throw new Exception("Element Action was not found");
            }
        }
        public override void RunCommand(object sender)
        {
            var engine = (IAutomationEngineInstance)sender;

            var vTimeout = int.Parse(v_Timeout.ConvertUserVariableToString(engine));
            var seleniumSearchParamRows = (from rw in v_SeleniumSearchParameters.AsEnumerable()
                                           where rw.Field <string>("Enabled") == "True" &&
                                           rw.Field <string>("Parameter Value").ToString() != ""
                                           select rw.ItemArray.Cast <string>().ToArray()).ToList();

            var     browserObject    = v_InstanceName.GetAppInstance(engine);
            var     seleniumInstance = (IWebDriver)browserObject;
            dynamic element          = CommandsHelper.FindElement(engine, seleniumInstance, seleniumSearchParamRows, v_SeleniumSearchOption, vTimeout);

            if (element == null && v_SeleniumElementAction != "Element Exists")
            {
                throw new ElementNotVisibleException("Unable to find element within the provided time limit");
            }

            if (v_SeleniumElementAction.Contains("Click"))
            {
                int seleniumWindowHeightY = seleniumInstance.Manage().Window.Size.Height;
                int elementPositionY      = ((IWebElement)element).Location.Y;
                if (elementPositionY > seleniumWindowHeightY)
                {
                    string scroll          = string.Format("window.scroll(0, {0})", elementPositionY);
                    IJavaScriptExecutor js = browserObject as IJavaScriptExecutor;
                    js.ExecuteScript(scroll);
                }
            }
            Actions actions = new Actions(seleniumInstance);

            switch (v_SeleniumElementAction)
            {
            case "Invoke Click":
                ((IWebElement)element).Click();
                break;

            case "Left Click":
                actions.Click((IWebElement)element).Perform();
                break;

            case "Right Click":
                actions.ContextClick((IWebElement)element).Perform();
                break;

            case "Middle Click":
                int userXAdjust = Convert.ToInt32((from rw in v_WebActionParameterTable.AsEnumerable()
                                                   where rw.Field <string>("Parameter Name") == "X Adjustment"
                                                   select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));

                int userYAdjust = Convert.ToInt32((from rw in v_WebActionParameterTable.AsEnumerable()
                                                   where rw.Field <string>("Parameter Name") == "Y Adjustment"
                                                   select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));

                var elementLocation        = ((IWebElement)element).Location;
                var seleniumWindowPosition = seleniumInstance.Manage().Window.Position;
                User32Functions.SendMouseMove(
                    (seleniumWindowPosition.X + elementLocation.X + userXAdjust).ToString(),
                    (seleniumWindowPosition.Y + elementLocation.Y + userYAdjust).ToString(),
                    v_SeleniumElementAction);

                break;

            case "Double Left Click":
                actions.DoubleClick((IWebElement)element).Perform();
                break;

            case "Set Text":
                string textToSet = (from rw in v_WebActionParameterTable.AsEnumerable()
                                    where rw.Field <string>("Parameter Name") == "Text To Set"
                                    select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine);


                string clearElement = (from rw in v_WebActionParameterTable.AsEnumerable()
                                       where rw.Field <string>("Parameter Name") == "Clear Element Before Setting Text"
                                       select rw.Field <string>("Parameter Value")).FirstOrDefault();

                string encryptedData = (from rw in v_WebActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Encrypted Text"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault();

                if (clearElement == null)
                {
                    clearElement = "No";
                }

                if (clearElement.ToLower() == "yes")
                {
                    ((IWebElement)element).Clear();
                }

                if (encryptedData == "Encrypted")
                {
                    textToSet = EncryptionServices.DecryptString(textToSet, "OPENBOTS");
                }

                string[] potentialKeyPresses = textToSet.Split('[', ']');

                Type        seleniumKeys   = typeof(OpenQA.Selenium.Keys);
                FieldInfo[] fields         = seleniumKeys.GetFields(BindingFlags.Static | BindingFlags.Public);
                string      finalTextToSet = "";

                //check if chunked string contains a key press command like {ENTER}
                foreach (string chunkedString in potentialKeyPresses)
                {
                    if (chunkedString == "")
                    {
                        continue;
                    }

                    if (fields.Any(f => f.Name.ToLower() == chunkedString.ToLower()) && textToSet.Contains("[" + chunkedString + "]"))
                    {
                        string keyPress = (string)fields.Where(f => f.Name.ToLower() == chunkedString.ToLower()).FirstOrDefault().GetValue(null);
                        finalTextToSet += keyPress;
                    }
                    else
                    {
                        var convertedChunk = chunkedString.ConvertUserVariableToString(engine);
                        finalTextToSet += convertedChunk;
                    }
                }
                ((IWebElement)element).SendKeys(finalTextToSet);
                break;

            case "Set Secure Text":
                var secureString = (from rw in v_WebActionParameterTable.AsEnumerable()
                                    where rw.Field <string>("Parameter Name") == "Secure String Variable"
                                    select rw.Field <string>("Parameter Value")).FirstOrDefault();

                string _clearElement = (from rw in v_WebActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Clear Element Before Setting Text"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault();

                var secureStrVariable = secureString.ConvertUserVariableToObject(engine, typeof(SecureString));

                if (secureStrVariable is SecureString)
                {
                    secureString = ((SecureString)secureStrVariable).ConvertSecureStringToString();
                }
                else
                {
                    throw new ArgumentException("Provided Argument is not a 'Secure String'");
                }

                if (_clearElement == null)
                {
                    _clearElement = "No";
                }

                if (_clearElement.ToLower() == "yes")
                {
                    ((IWebElement)element).Clear();
                }

                string[] _potentialKeyPresses = secureString.Split('[', ']');

                Type        _seleniumKeys   = typeof(OpenQA.Selenium.Keys);
                FieldInfo[] _fields         = _seleniumKeys.GetFields(BindingFlags.Static | BindingFlags.Public);
                string      _finalTextToSet = "";

                //check if chunked string contains a key press command like {ENTER}
                foreach (string chunkedString in _potentialKeyPresses)
                {
                    if (chunkedString == "")
                    {
                        continue;
                    }

                    if (_fields.Any(f => f.Name.ToLower() == chunkedString.ToLower()) && secureString.Contains("[" + chunkedString + "]"))
                    {
                        string keyPress = (string)_fields.Where(f => f.Name.ToLower() == chunkedString.ToLower()).FirstOrDefault().GetValue(null);
                        _finalTextToSet += keyPress;
                    }
                    else
                    {
                        var convertedChunk = chunkedString.ConvertUserVariableToString(engine);
                        _finalTextToSet += convertedChunk;
                    }
                }
                ((IWebElement)element).SendKeys(_finalTextToSet);
                break;

            case "Get Options":
                string applyToVarName = (from rw in v_WebActionParameterTable.AsEnumerable()
                                         where rw.Field <string>("Parameter Name") == "Variable Name"
                                         select rw.Field <string>("Parameter Value")).FirstOrDefault();


                string attribName = (from rw in v_WebActionParameterTable.AsEnumerable()
                                     where rw.Field <string>("Parameter Name") == "Attribute Name"
                                     select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine);

                var optionsItems = new List <string>();
                var ele          = (IWebElement)element;
                var select       = new SelectElement(ele);
                var options      = select.Options;

                foreach (var option in options)
                {
                    var optionValue = option.GetAttribute(attribName);
                    optionsItems.Add(optionValue);
                }

                optionsItems.StoreInUserVariable(engine, applyToVarName, typeof(List <string>));

                break;

            case "Select Option":
                string selectionType = (from rw in v_WebActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Selection Type"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault();

                string selectionParam = (from rw in v_WebActionParameterTable.AsEnumerable()
                                         where rw.Field <string>("Parameter Name") == "Selection Parameter"
                                         select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine);

                seleniumInstance.SwitchTo().ActiveElement();

                var el = (IWebElement)element;
                var selectionElement = new SelectElement(el);

                switch (selectionType)
                {
                case "Select By Index":
                    selectionElement.SelectByIndex(int.Parse(selectionParam));
                    break;

                case "Select By Text":
                    selectionElement.SelectByText(selectionParam);
                    break;

                case "Select By Value":
                    selectionElement.SelectByValue(selectionParam);
                    break;

                case "Deselect By Index":
                    selectionElement.DeselectByIndex(int.Parse(selectionParam));
                    break;

                case "Deselect By Text":
                    selectionElement.DeselectByText(selectionParam);
                    break;

                case "Deselect By Value":
                    selectionElement.DeselectByValue(selectionParam);
                    break;

                case "Deselect All":
                    selectionElement.DeselectAll();
                    break;

                default:
                    throw new NotImplementedException();
                }
                break;

            case "Get Text":
            case "Get Attribute":
            case "Get Count":
                string VariableName = (from rw in v_WebActionParameterTable.AsEnumerable()
                                       where rw.Field <string>("Parameter Name") == "Variable Name"
                                       select rw.Field <string>("Parameter Value")).FirstOrDefault();

                string attributeName = (from rw in v_WebActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Attribute Name"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine);

                string elementValue;
                if (v_SeleniumElementAction == "Get Text")
                {
                    elementValue = element.Text;
                }
                else if (v_SeleniumElementAction == "Get Count")
                {
                    elementValue = "1";
                    if (element is ReadOnlyCollection <IWebElement> )
                    {
                        elementValue = ((ReadOnlyCollection <IWebElement>)element).Count().ToString();
                    }
                }
                else
                {
                    elementValue = ((IWebElement)element).GetAttribute(attributeName);
                }

                elementValue.StoreInUserVariable(engine, VariableName, typeof(string));
                break;

            case "Get Matching Element(s)":
                var variableName = (from rw in v_WebActionParameterTable.AsEnumerable()
                                    where rw.Field <string>("Parameter Name") == "Variable Name"
                                    select rw.Field <string>("Parameter Value")).FirstOrDefault();

                if (!(element is IWebElement))
                {
                    //create element list
                    List <IWebElement> elementList = new List <IWebElement>();
                    foreach (IWebElement item in element)
                    {
                        elementList.Add(item);
                    }
                    elementList.StoreInUserVariable(engine, variableName, typeof(List <IWebElement>));
                }
                else
                {
                    ((IWebElement)element).StoreInUserVariable(engine, variableName, typeof(IWebElement));
                }
                break;

            case "Get Table":
                var DTVariableName = (from rw in v_WebActionParameterTable.AsEnumerable()
                                      where rw.Field <string>("Parameter Name") == "Variable Name"
                                      select rw.Field <string>("Parameter Value")).FirstOrDefault();

                // Get HTML (Source) of the Element
                string       tableHTML = ((IWebElement)element).GetAttribute("innerHTML").ToString();
                HtmlDocument doc       = new HtmlDocument();

                //Load Source (String) as HTML Document
                doc.LoadHtml(tableHTML);

                //Get Header Tags
                var       headers = doc.DocumentNode.SelectNodes("//tr/th");
                DataTable DT      = new DataTable();

                //If headers found
                if (headers != null && headers.Count != 0)
                {
                    // add columns from th (headers)
                    foreach (HtmlNode header in headers)
                    {
                        DT.Columns.Add(Regex.Replace(header.InnerText, @"\t|\n|\r", "").Trim());
                    }
                }
                else
                {
                    var columnsCount = doc.DocumentNode.SelectSingleNode("//tr[1]").ChildNodes.Where(node => node.Name == "td").Count();
                    DT.Columns.AddRange((Enumerable.Range(1, columnsCount).Select(dc => new DataColumn())).ToArray());
                }

                // select rows with td elements and load each row (containing <td> tags) into DataTable
                foreach (var row in doc.DocumentNode.SelectNodes("//tr[td]"))
                {
                    DT.Rows.Add(row.SelectNodes("td").Select(td => Regex.Replace(td.InnerText, @"\t|\n|\r", "").Trim()).ToArray());
                }

                DT.StoreInUserVariable(engine, DTVariableName, typeof(DataTable));
                break;

            case "Clear Element":
                ((IWebElement)element).Clear();
                break;

            case "Switch to Frame":
                if (seleniumSearchParamRows.Count == 0)
                {
                    seleniumInstance.SwitchTo().DefaultContent();
                }
                else
                {
                    seleniumInstance.SwitchTo().Frame((IWebElement)element);
                }
                break;

            case "Wait For Element To Exist":
                break;

            case "Element Exists":
                string existsBoolVariableName = (from rw in v_WebActionParameterTable.AsEnumerable()
                                                 where rw.Field <string>("Parameter Name") == "Variable Name"
                                                 select rw.Field <string>("Parameter Value")).FirstOrDefault();

                if (element == null)
                {
                    false.StoreInUserVariable(engine, existsBoolVariableName, typeof(bool));
                }
                else
                {
                    true.StoreInUserVariable(engine, existsBoolVariableName, typeof(bool));
                }

                break;

            default:
                throw new Exception("Element Action was not found");
            }
        }