Unable to dismiss a message box automatically in vb.net

528 Views Asked by At

I am trying a simple code in Silk4Net using VB.Net. I have automated launching of a calculator. Before the numbers can be typed, a message box appears. I am unable to find a way to dismiss the message box automatically. I want to be able to recognize the message box and either push it to the back or dismiss it totally.

The code is as below:

    <TestMethod()>
Public Sub TestMethod1()
    With _desktop.Window("Calculator")
        .SetActive()
        generateMsg()
        .PushButton("Clear").Select()
        .PushButton("3").Select()
        .PushButton("5").Select()
    End With

End Sub

Public Sub generateMsg()
    Thread.Sleep(2000)
    With _desktop.Window(MsgBox("Test", MsgBoxStyle.Critical, "Test"))
        For Each p As Process In Process.GetProcesses
            If p.MainWindowTitle.Contains("Test") Then
                p.Kill()
            End If
        Next

        'With .Dialog("Test")
        '    '.PushButton("OK").Select()

        'End With
        ' .Close()
    End With
End Sub

Any help would be much appreciated. Thanks.

1

There are 1 best solutions below

4
On

Updated answer

You could add a timer to the code that uses SendKeys.SendWait - like this - adapting it a little for your test environment as I'm not sure about Silk4Net tbh

Dim WithEvents timer1 As New System.Timers.Timer
timer1.Interval = 5000
timer1.Enabled = True
MsgBox("Hello. I will go bye-bye in 5 seconds.")
timer1.Enabled = False

And as a separate sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles timer1.Elapsed
    SendKeys.SendWait("{ENTER}")
End Sub