2023-01-20

Using Selenium Alert Handler in VBA with Chrome

I've placed a serial number in a box and clicked the button, and a popup alert appears saying that serial number is not found, OK to continue.

TagSerialBox.Clear        ' Clear the default text already in the box
On Error GoTo AlertHandler  ' Go here if serial number not found
TagSerialBox.SendKeys serial ' Enter the serial number into the box
 Dim ClickPreview As selenium.WebElement  ' This is the item displayed
 Set ClickPreview = Partssite.FindElementById("fetchlink")   ' Focus on the link
    ClickPreview.Click       ' Click the link


AlertHandler: 
    MsgBox "Serial# " & serial & " not found, need to re-enter"
driver.SwitchToAlert().Accept    ' Should send OK to the alert popup and continue.

This code works fine when the serial number is found, but when it isn't found, it goes to the Alert Handler as expected and

  • the MsgBox works fine
  • the execution fails on the "driver.SwitchToAlert().Accept" line with a Run-time error '424': Object required. I can't figure out what to do from the Selenium documentation. Can ayone help with this? Thanks.


No comments:

Post a Comment