'VBA Selenium with Chrome - Want to add Error Handler in VBA only

  1. Want to add Two Things in Error Handler, If script get stuck in any line, like if Webpage does not meet its requirement, it shows the Alert pop
  2. for this WebPage Requirements is like, Name character length must be >3 or Mobile number digits must be = 10
  3. Then I want to refresh ‪bot.Refresh the page then want to - Click OK (or Accept) in the Alert Popup bot.SwitchToAlert.Accept then Sub End - all this stuff in an Error Handling.‬
  4. After a successful run of Error Handling, the script has to run from the beginning (from #Patient Name)
  5. I want to add a Column in Excel where which line got an error, gave me Not Done and which got no error gave me Done
Sub Automate()
    Dim bot As WebDriver
    Set bot = New WebDriver
    bot.Start "chrome"
    bot.Get "/"
    
'#Patient Name
    bot.FindElementByName("patient_name").SendKeys "Value"

'#Age-in
    If Sheet1.Cells(row, 4) = "Years" Then
        bot.FindElementById("age_year").Click
        bot.FindElementByName("age").SendKeys "Value"
    Else
    If Sheet1.Cells(row, 4) = "Months" Then
        bot.FindElementById("age_month").Click
        bot.FindElementByName("age").SendKeys "Value"
    Else
    If Sheet1.Cells(row, 4) = "Days" Then
        bot.FindElementById("age_day").Click
        bot.FindElementByName("age").SendKeys "Value"
    End If
    End If
    End If

'#Mobile Number
    bot.FindElementById("contact_number").SendKeys "Value"

'#Gender
    If Sheet1.Cells(row, 6) = "Male" Then
        Set ListDD = bot.FindElementById("gender")
        ListDD.AsSelect.SelectByText "Value"
    Else
    If Sheet1.Cells(row, 6) = "Female" Then
        Set ListDD = bot.FindElementById("gender")
        ListDD.AsSelect.SelectByText "Value"
    Else
    If Sheet1.Cells(row, 6) = "Transgender" Then
        Set ListDD = bot.FindElementById("gender")
        ListDD.AsSelect.SelectByText "Value"
    End If
    End If
    End If
End Sub

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