0
votes

I working with WatIn and i saving files with saveAs dialog,but when i lock windows/pc this process is stops, i need to cast the Invoke to SendMessage that this process will still run when my pc is lock.

Is there a way to do this?

Pice of code with Invoke

  private static void ClickSaveAs(AutomationElement mainWindow, AutomationElementCollection dialogElements, string filename)
        {


            foreach (AutomationElement element in dialogElements)
            {

                if (element.Current.Name.Equals("Save"))
                {
                    AutomationElementCollection dialogSubElements = element.FindAll(TreeScope.Children, Automation.ContentViewCondition);
                    InvokePattern clickPatternForSaveDropdown = (InvokePattern)dialogSubElements[0].GetCurrentPattern(AutomationPattern.LookupById(10000));
                //I need to change this to..
                   clickPatternForSaveDropdown.Invoke();

//This
                    //start
                    int intWhdr = FindWindow("IEFrame", "");
                    int currChild = FindWindowEx(intWhdr, 0, "", "Frame Notification Bar");
                    currChild = 104755016;
                    int intRes1 = SendMessage(currChild, WM_LBUTTONDOWN, 0, 0);
                    System.Threading.Thread.Sleep(100);
                    intRes1 = SendMessage(currChild, WM_LBUTTONUP, 0, 1);
                    System.Threading.Thread.Sleep(200);
                    //end
                    Thread.Sleep(1500);

                    AutomationElementCollection dialogElementsInMainWindow = mainWindow.FindAll(TreeScope.Children, Condition.TrueCondition);
                    foreach (AutomationElement currentMainWindowDialogElement in dialogElementsInMainWindow)
                    {
                        if (currentMainWindowDialogElement.Current.LocalizedControlType == "menu")
                        {
                            // first array element 'Save', second array element 'Save as', third second array element    'Save and open'
                            InvokePattern clickMenu = (InvokePattern)currentMainWindowDialogElement.FindAll(TreeScope.Children, Condition.TrueCondition)[1].GetCurrentPattern(AutomationPattern.LookupById(10000));
                            clickMenu.Invoke();
                            Thread.Sleep(1);
                            ControlSaveDialog(mainWindow, filename);
                            break;
                            //strt


                            //end
                        }
                    }
                }
            }
        }
1

1 Answers

0
votes

Watin will not work when machine is locked. Since it uses, Microsoft.mshtml and Interop.SHDocVw binary references. These binaries are COM components and needs an interactive UI. For sample you can try out login itself instead of download. Start the test and lock the machine and then unlock. Observe the result, it will be failed throwing an error like COM exception.... Try using Reg keys update to unlock the machine permanently as an option...