Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98814

Check for the alert in selenium VBA

$
0
0

I am trying the following code

Private bot As New Selenium.ChromeDriver

Sub Test()
Dim arr(), ws As Worksheet, i As Long

Const NO_JS_PROFILE As String = "C:\Users\Future\AppData\Local\Google\Chrome\User Data\Profile 1"
Const JS_PROFILE As String = "C:\Users\Future\AppData\Local\Google\Chrome\User Data\Default"

Set bot = New ChromeDriver
Set ws = ActiveSheet
arr = Application.Transpose(ws.Range("A2:A"& ws.Cells(Rows.Count, 1).End(xlUp).Row))

With bot
    .SetProfile JS_PROFILE, True
    .Get "https://web.whatsapp.com/send?phone="& arr(1)

I would loop through some mobile numbers stored in the array .. and sometimes there are invalid numbers so I encountered alert message that the number is invlaid How can I catch this alert and debug in the immediate window that the number is invalid and skip to the next number

I tried the following function

Function IsDialogPresent(driver As WebDriver) As Boolean
On Error Resume Next
Debug.Print driver.Title
IsDialogPresent = (26 = Err.Number)
End Function

and in the main code I declared a variable

Dim dlg As Alert

then I used

  If IsDialogPresent(bot) Then
    Set dlg = .SwitchToAlert(Raise:=False)

 Stop
    'Close Alert
    'dlg.Dismiss
 End If

but the function doesn't return True as I expected (so it seems not to be alert like I know)


Viewing all articles
Browse latest Browse all 98814

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>