This commit is contained in:
louiscklaw
2025-02-01 01:59:56 +08:00
parent b3da7aaef5
commit 8719fe58b8
310 changed files with 6332 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
Attribute VB_Name = "usage_alert"
Private Assert As New Selenium.Assert
Private Sub Handle_Alerts()
Dim driver As New ChromeDriver
driver.SetCapability "unexpectedAlertBehaviour", "ignore"
driver.Get "http://the-internet.herokuapp.com/javascript_alerts"
' Display alert
driver.FindElementByCss("#content li:nth-child(2) button").Click
' Set the context on the alert dialog
Set dlg = driver.SwitchToAlert(Raise:=False)
' Assert an alert is present and the message
Assert.False dlg Is Nothing, "No alert present!"
Assert.Equals "I am a JS Confirm", dlg.Text
' Close alert
dlg.Accept
driver.Quit
End Sub
'Returns true if an alert is present, false otherwise
' driver: web driver
Private Function IsDialogPresent(driver As WebDriver) As Boolean
On Error Resume Next
T = driver.title
IsDialogPresent = (26 = Err.Number)
End Function