웹 페이지에서 일부 JavaScript를 실행하는 간단한 봇인 WinForms WebView2 프로젝트가 있습니다. JS를 사용하여 웹 페이지의 요소를 클릭하고 파일을 다운로드하고 있습니다. 웹 사이트에서 "페이지에서 나가시겠습니까?"라는 메시지가 표시됩니다. 대화 상자에서 웹 페이지를 종료하고 파일을 다운로드 할 것인지 확인하기 위해 RETURN 키보드를 눌러 보내려고합니다.
Windows 작업 스케줄러를 사용하여 자동으로 실행하고 싶습니다. 이 방법은 서버에 원격으로 연결되어 있고 창이 최소화되지 않는 한 작동합니다. 그러나 서버에 원격으로 연결되어 있지 않으면 Enter 키를 누르면 반환되고 오류가 발생합니다.
이 코드를 SendKeys로 시도했습니다.
//Get Webview proccess
Process p = Process.GetProcessesByName("msedgewebview2").FirstOrDefault();
if (p != null)
{
IntPtr h = p.MainWindowHandle;
SetForegroundWindow(h);
printToTextbox("pressed ENTER key");
SendKeys.SendWait("{ENTER}");
await checkDownloadFinished();
}
봇을 시작한 다음 원격 세션을 종료합니다. 내가 돌아 왔을 때 프로그램이 도달했을 때이 오류가 발생합니다.SendKeys.SendWait("{ENTER}");
System.ComponentModel.Win32Exception: 'Access is denied'
또한 Nuget 패키지 InputSimulator를 시도했습니다.
Process p = Process.GetProcessesByName("msedgewebview2").FirstOrDefault();
if (p != null)
{
IntPtr h = p.MainWindowHandle;
SetForegroundWindow(h);
printToTextbox("pressed ENTER key");
InputSimulator s = new InputSimulator();
s.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.RETURN);
await checkDownloadFinished();
}
동일한 절차에 따라 봇을 시작하고 원격 세션을 종료합니다. 돌아 오면 다음 오류가 발생합니다.
System.Exception: 'Some simulated input commands were not sent successfully. The most common reason
for this happening are the security features of Windows including User Interface Privacy Isolation
(UIPI). Your application can only send commands to applications of the same or lower elevation.
Similarly certain commands are restricted to Accessibility/UIAutomation applications. Refer to the
project home page and the code samples for more information.'
키 입력을 보내는 다른 C # 호환 방법이 있습니까? 아니면 대화 상자가 나타나지 않도록하는 방법이 있습니까? 감사합니다!
당신은 잘못하고있어 :-)
살펴보아야합니다 : CoreWebView2.ScriptDialogOpening Event .
은 scriptdialogopening
과의있는 EventArgs가 Accept()
클릭 방법을 Ok
대화 상자에.
eventargs 링크는 다음과 같습니다. CoreWebView2ScriptDialogOpeningEventArgs
이제 SendKeys
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다