Tópico anterior Próximo tópico Novo tópico
C#
#495736 - 25/11/2020 18:52:47 | ||||
![]() ATSILVA SAO PAULO Cadast. em:Março/2014 ![]() |
Última edição em 25/11/2020 20:12:13 por ATSILVA Anexos estao visíveis somente para usuários registrados Tenho aplicação em C# que manipula um site (infelizmente o mesmo ainda não possui API) e preciso enviar um clique no botão OK em uma MessageBox de confirmação que aparece quando vou excluir um produto. Segue imagem da caixa de mensagem.Alguém sabe como fazer? |
|||
#495739 - 25/11/2020 21:24:38 | ||||
![]() FABRICIOWEB BELO HORIZONTE Cadast. em:Novembro/2011 ![]() |
Citação: : Tenho aplicação em C# que manipula um site (infelizmente o mesmo ainda não possui API) e preciso enviar um clique no botão OK em uma MessageBox de confirmação que aparece quando vou excluir um produto. Segue imagem da caixa de mensagem. Alguém sabe como fazer? basta vc pegar o id desse botão webBrowser1.Document.GetElementById('ID DO BOTAO').InvokeMember('click'); |
|||
#495740 - 26/11/2020 09:23:23 | ||||
![]() ATSILVA SAO PAULO Cadast. em:Março/2014 ![]() |
Última edição em 26/11/2020 10:00:55 por ATSILVA FABRICIOWEB, obrigado, esse comando webBrowser1.Document.GetElementById('ID DO BOTAO').InvokeMember('click'); ja foi dado.É após esse comando que aparece a caixa de mensagem com botão OK para clicar, esse clique que não consigo fazer. |
|||
#495755 - 28/11/2020 11:34:54 | ||||
![]() ATSILVA SAO PAULO Cadast. em:Março/2014 ![]() |
Se alguém souber como efetuar o clique no botão OK da caixa de mensagem (veja imagem primeiro post) fico agradecido.
|
|||
Resposta escolhida #495773 - 03/12/2020 12:17:20 | ||||
![]() FABRICIOWEB BELO HORIZONTE Cadast. em:Novembro/2011 ![]() |
Citação: : Se alguém souber como efetuar o clique no botão OK da caixa de mensagem (veja imagem primeiro post) fico agradecido. não tenho certeza doque vou postar aqui nao testei using System.Runtime.InteropServices class SurroundingClass { // api constant declarations... const long WM_GETTEXT = 0xD; const long WM_GETTEXTLENGTH = 0xE; const long GW_ENABLEDPOPUP = 6; const long BM_CLICK = 0xF5&; const long GW_CHILD = 5; const long GW_HWNDNEXT = 2; // function to retrieve the popup window associated with the form, as well as to find the child windows of the popup... [System.Runtime.InteropServices.DllImport('user32.dll')] private static extern IntPtr GetWindow(IntPtr hWnd, long uCmd); // sendmessage overload that is used to send messages to the button on the dialog window... [System.Runtime.InteropServices.DllImport('user32.dll')] private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, ref IntPtr lParam); // sendmessage overloads used to retrieve the window text... [System.Runtime.InteropServices.DllImport('user32.dll')] private static extern IntPtr SendMessageA(IntPtr hWnd, int Msg, IntPtr wParam, ref IntPtr lParam); [DllImport('User32.dll', CharSet = CharSet.Auto, Entrypoint = 'SendMessage')] public static IntPtr SendMessageString(IntPtr hwnd, int wMsg, int wparam, System.Text.StringBuilder lparam) { } // these next three functions are used to enumerate the Windows handles of all Windows sited on the specified parent... private static ArrayList GetChildWindowHandles(IntPtr ParentWindowHandle) { bool b; IntPtr ptrChild; ArrayList clsRet = new ArrayList(); // get first child handle... ptrChild = GetChildWindowHandle(ParentWindowHandle); while (!ptrChild.Equals(IntPtr.Zero)) { // add to collection of handles... clsRet.Add(ptrChild); // get next child... ptrChild = GetNextWindowHandle(ptrChild); } // return... return clsRet; } private static IntPtr GetChildWindowHandle(IntPtr ParentWindowHandle) { return GetWindow(ParentWindowHandle, GW_CHILD); } private static IntPtr GetNextWindowHandle(IntPtr CurrentWindowhandle) { return GetWindow(CurrentWindowhandle, GW_HWNDNEXT); } // this function returns the text of the window, used so that we can confirm that we have the right dialog window... private string GetWindowText(IntPtr WindowHandle) { IntPtr ptrRet; IntPtr ptrLength; // get length for buffer... ptrLength = SendMessageA(WindowHandle, WM_GETTEXTLENGTH, IntPtr.Zero, ref IntPtr.Zero); // create buffer for return value... System.Text.StringBuilder sb = new System.Text.StringBuilder(ptrLength.ToInt32() + 1); // get window text... ptrRet = SendMessageString(WindowHandle, WM_GETTEXT, ptrLength.ToInt32() + 1, sb); // get return value... return sb.ToString(); } // this function sends a button click message to the specified window... private static void ClickButton(IntPtr WindowHandle) { SendMessage(WindowHandle, BM_CLICK, 0, ref IntPtr.Zero); } private void LookForAndCloseIEPopup() { // get a handle to any popup window associated with the main form (as is a popup window // displayed by the Web browser control)... IntPtr ptrDialogWindow = GetWindow(this.Handle, GW_ENABLEDPOPUP); // if the popup window is one displayed by the browser, then send the close message to the window... if (GetWindowText(ptrDialogWindow) == 'Microsoft Internet Explorer') ClosePopup(ptrDialogWindow); } private void ClosePopup(IntPtr WindowHandle) { ArrayList clsChildHandles = GetChildWindowHandles(WindowHandle); // look through all of the child handles of the window for an 'OK' button (this method // can also be used to gather more specific information about the dialog itself, such as // the message being displayed)... foreach (IntPtr ptrHandle in clsChildHandles) { // if the OK button is found, click it... if (GetWindowText(ptrHandle) == 'OK') { ClickButton(ptrHandle); break; } } } } Call LookForAndCloseIEPopup() |
|||
Tópico anterior Próximo tópico Novo tópico