我使用WatIn并使用saveAs对话框保存文件,但是当我锁定windows / pc时,此过程停止,我需要将Invoke转换为SendMessage,当我的电脑锁定时,此过程仍会运行。
有办法做到这一点吗?
使用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
}
}
}
}
}
答案 0 :(得分:0)
当机器锁定时,Watin将无法工作。由于它使用了Microsoft.mshtml和Interop.SHDocVw二进制引用。这些二进制文件是COM组件,需要交互式UI。对于示例,您可以尝试登录而不是下载。开始测试并锁定机器然后解锁。观察结果,它将失败抛出像COM异常的错误....尝试使用Reg键更新永久解锁机器作为选项......