'VBA Selenium with Chrome - Want to add Error Handler in VBA only
- Want to add Two Things in Error Handler, If script get
stuckin any line, like if Webpage does not meet its requirement, it shows theAlert pop - for this WebPage Requirements is like, Name character length must be >3 or Mobile number digits must be = 10
- Then I want to refresh
bot.Refreshthe page then want to - Click OK (or Accept) in the Alert Popupbot.SwitchToAlert.AcceptthenSub End- all this stuff in an Error Handling. - After a successful run of Error Handling, the script has to run from the beginning (from #Patient Name)
- 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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

