private async Task RunCommandActions(IHTMLElement element, object sender, InternetExplorer browserInstance) { var engine = (IAutomationEngineInstance)sender; switch (v_WebAction) { case "Fire onmousedown event": ((IHTMLElement3)element).FireEvent("onmousedown"); break; case "Fire onmouseover event": ((IHTMLElement3)element).FireEvent("onmouseover"); break; case "Invoke Click": element.click(); IECreateBrowserCommand.WaitForReadyState(browserInstance); break; case "Left Click": case "Middle Click": case "Right Click": int elementXposition = FindElementXPosition(element); int elementYposition = FindElementYPosition(element); //inputs need to be validated string userXAdjustString = (from rw in v_WebActionParameterTable.AsEnumerable() where rw.Field <string>("Parameter Name") == "X Adjustment" select rw.Field <string>("Parameter Value")).FirstOrDefault(); int userXAdjust = (int)await userXAdjustString.EvaluateCode(engine); string userYAdjustString = (from rw in v_WebActionParameterTable.AsEnumerable() where rw.Field <string>("Parameter Name") == "Y Adjustment" select rw.Field <string>("Parameter Value")).FirstOrDefault(); int userYAdjust = (int)await userYAdjustString.EvaluateCode(engine); var ieClientLocation = User32Functions.GetWindowPosition(new IntPtr(browserInstance.HWND)); var mouseX = (elementXposition + ieClientLocation.left + 10) + userXAdjust; // + 10 gives extra padding var mouseY = (elementYposition + ieClientLocation.top + 90 + SystemInformation.CaptionHeight) + userYAdjust; // +90 accounts for title bar height var mouseClick = v_WebAction; User32Functions.SendMouseMove(mouseX, mouseY, v_WebAction); break; case "Set Attribute": string setAttributeName = (from rw in v_WebActionParameterTable.AsEnumerable() where rw.Field <string>("Parameter Name") == "Attribute Name" select rw.Field <string>("Parameter Value")).FirstOrDefault(); string valueToSet = (from rw in v_WebActionParameterTable.AsEnumerable() where rw.Field <string>("Parameter Name") == "Value To Set" select rw.Field <string>("Parameter Value")).FirstOrDefault(); valueToSet = (string)await valueToSet.EvaluateCode(engine); element.setAttribute(setAttributeName, valueToSet); break; case "Set Text": string setTextAttributeName = "value"; string textToSet = (from rw in v_WebActionParameterTable.AsEnumerable() where rw.Field <string>("Parameter Name") == "Text To Set" select rw.Field <string>("Parameter Value")).FirstOrDefault(); textToSet = (string)await textToSet.EvaluateCode(engine); element.setAttribute(setTextAttributeName, textToSet); break; case "Get Attribute": string attributeName = (from rw in v_WebActionParameterTable.AsEnumerable() where rw.Field <string>("Parameter Name") == "Attribute Name" select rw.Field <string>("Parameter Value")).FirstOrDefault(); string variableName = (from rw in v_WebActionParameterTable.AsEnumerable() where rw.Field <string>("Parameter Name") == "Variable Name" select rw.Field <string>("Parameter Value")).FirstOrDefault(); string convertedAttribute = Convert.ToString(element.getAttribute(attributeName)); convertedAttribute.SetVariableValue(engine, variableName); break; } }
private void RunCommandActions(IHTMLElement element, object sender, InternetExplorer browserInstance) { if (v_WebAction == "Fire onmousedown event") { ((IHTMLElement3)element).FireEvent("onmousedown"); } else if (v_WebAction == "Fire onmouseover event") { ((IHTMLElement3)element).FireEvent("onmouseover"); } else if (v_WebAction == "Invoke Click") { element.click(); IEBrowserCreateCommand.WaitForReadyState(browserInstance); } else if ((v_WebAction == "Left Click") || (v_WebAction == "Middle Click") || (v_WebAction == "Right Click")) { int elementXposition = FindElementXPosition(element); int elementYposition = FindElementYPosition(element); //inputs need to be validated 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()); 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()); var ieClientLocation = User32Functions.GetWindowPosition(new IntPtr(browserInstance.HWND)); SendMouseMoveCommand newMouseMove = new SendMouseMoveCommand(); newMouseMove.v_XMousePosition = ((elementXposition + ieClientLocation.left + 10) + userXAdjust).ToString(); // + 10 gives extra padding newMouseMove.v_YMousePosition = ((elementYposition + ieClientLocation.top + 90 + System.Windows.Forms.SystemInformation.CaptionHeight) + userYAdjust).ToString(); // +90 accounts for title bar height newMouseMove.v_MouseClick = v_WebAction; newMouseMove.RunCommand(sender); } else if (v_WebAction == "Set Attribute") { string attributeName = (from rw in v_WebActionParameterTable.AsEnumerable() where rw.Field <string>("Parameter Name") == "Attribute Name" select rw.Field <string>("Parameter Value")).FirstOrDefault(); string valueToSet = (from rw in v_WebActionParameterTable.AsEnumerable() where rw.Field <string>("Parameter Name") == "Value To Set" select rw.Field <string>("Parameter Value")).FirstOrDefault(); valueToSet = valueToSet.ConvertToUserVariable(sender); element.setAttribute(attributeName, valueToSet); } else if (v_WebAction == "Set Text") { string attributeName = "value"; string textToSet = (from rw in v_WebActionParameterTable.AsEnumerable() where rw.Field <string>("Parameter Name") == "Text To Set" select rw.Field <string>("Parameter Value")).FirstOrDefault(); textToSet = textToSet.ConvertToUserVariable(sender); element.setAttribute(attributeName, textToSet); } else if (v_WebAction == "Get Attribute") { string attributeName = (from rw in v_WebActionParameterTable.AsEnumerable() where rw.Field <string>("Parameter Name") == "Attribute Name" select rw.Field <string>("Parameter Value")).FirstOrDefault(); string variableName = (from rw in v_WebActionParameterTable.AsEnumerable() where rw.Field <string>("Parameter Name") == "Variable Name" select rw.Field <string>("Parameter Value")).FirstOrDefault(); string convertedAttribute = Convert.ToString(element.getAttribute(attributeName)); convertedAttribute.StoreInUserVariable(sender, variableName); } }