'VBA Selenium - Error Handler working only once in a loop

In 1st run after error (after appearing PopUp) its going to '#5 ErrorHandler: which is good,

But in 2nd run after error (after appearing PopUp) its continuing to run from '#2 Patient Name:

I need to add more errorhandlersss to this script, like another one will come for '#3 to #4 n so on,

but firstly I need errorhandler only for line '#1 to #2

Please suggest your suggestion as per this my requirement.


Sub Update_Status()
Dim bot As New WebDriver
bot.START "Chrome"
bot.Get "https://www.ABCSite.in/"
 
    bot.FindElementById("username").SendKeys "USERID"
    bot.FindElementById("passwordd").SendKeys "PASSWORD"
    bot.FindElementById("loginbtn").Click
 
 

For i = 4 To x
 
'-------------------#1--------------------------
'SRF already entered or Wrong SRF
On Error GoTo ErrorHandler:
 
'Add Record from SRF Portal
    bot.FindElementById("home").Click
 
'SRF ID
    bot.FindElementById("srf_id").WaitDisplayed(True, 2000).SendKeys "Value"
    bot.FindElementById("btn").Click
    bot.Wait 1500
'----------<PopUp Appears>---------------
 
'-------------------#2--------------------------
 
'Patient Name
    bot.FindElementById("patient_name").SendKeys "Value"
'Patient ID
    bot.FindElementById("patient_id").SendKeys "Value"
 
'-------------------#3--------------------------
 
'#Passport Number
    bot.FindElementById("passport_number").WaitDisplayed(True).SendKeys "Value"
 
'-------------------#4--------------------------
 
    bot.FindElementById("btn").Click
    Sheet1.Cells(i, 41).Value = "Done"
 
nxtRow:
Next i
 
Exit Sub
 
'-------------------#5--------------------------
ErrorHandler:
            bot.Wait 1000
            bot.SwitchToAlert.Accept
            Sheet1.Cells(i, 41).Value = "Skipped"
            GoTo nxtRow
 
End Sub

I didn't understand that if its work in 1st run, why its not working in 2nd run ?? VBA Error: enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source