1

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.

Pallavi Prasad
  • 577
  • 2
  • 9
  • 28
  • You are displaying a `MsgBox` as part of your test script. What are you trying to achieve with that? – tehlexx Feb 17 '16 at 12:41
  • just trying to handle a msgbox programatically – Pallavi Prasad Feb 18 '16 at 11:42
  • If you remove the code form the script that is creating the MsgBox, you don't have to handle it. Handling it form the script is going to be close to impossible, as the MsgBox call is probably synchronous, thus blocking your script from executing while it's open. You could try creating the message box form a different thread, but still I think it's a bad idea to create a UI in your test scripts. – tehlexx Feb 18 '16 at 12:00
  • I agree with @tehlexx: the test program should test a different program, not itself. – Thomas Weller Mar 01 '16 at 11:02

1 Answers1

-1

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
David Wilson
  • 4,369
  • 3
  • 18
  • 31