Bonjour,

Avez-vous une solution pour cliquer sur le bouton "Ok" sur une fenetre popup générée par la fonction alert() de javascript ?

Voici un exemple : soit une page html générant un popup en cliquant sur le bouton interrogé :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
<html>
<body>
<input class="bouton" id="e160_btnINT" onclick="alert()" type="button" value="Interroger">
</body>
</html>
le popup généré a pour titre "Message de la page Web", j'ai appliqué les codes VBA ci-dessous pour essayer de faire disparaître le fenetre popup sans succès ( aussi bien avec la fonction SendMessage que SendKeys "{ENTER}" :
Auriez-vous une autre idée?

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Option Explicit
'---------------------------------------------------------
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEX Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Public Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
 
Public Const BT_CLICK = &HF5
Public Const WM_CHAR = &H102
 
Sub CliquePopUp(ByVal TitrePopup As String)
Dim hwnd_PopUp As Long, hwnd_Ok As Long
Dim k As Integer
 
Do
    hwnd_PopUp = FindWindow(vbNullString, TitrePopup)      'ici
    k = k + 1
Loop While hwnd_PopUp = 0 And k <= 10000
'----------------------------------------------------------------
If hwnd_PopUp <> 0 Then
    hwnd_Ok = FindWindowEX(hwnd_PopUp, 0&, "Button", "&OK")    'ou simplement "OK" (caption du bouton)
    Putfocus hwnd_Ok
    SendMessage hwnd_Ok, BT_CLICK, 0&, 0&
    'SendKeys "{ENTER}"
End If
End Sub
 
'Pour tester (adapte la caption de ton popup)
Sub test()
CliquePopUp "Message de la page Web"
End Sub
Merci pour vos suggestions,
Lian