stuck
任何一行,就像网页不符合要求一样,它会显示Alert pop
bot.Refresh
页面然后想要 - 在警报弹出窗口中单击确定(或接受)bot.SwitchToAlert.Accept
然后Sub End
- 所有这些内容都在错误处理中。Sub Automate()
Dim bot As WebDriver
Set bot = New WebDriver
bot.Start "chrome"
bot.Get "/"
'#Patient Name
bot.FindElementByName("patient_name").SendKeys (Sheet1.Cells(row, 2).Value)
'#Age-in
If Sheet1.Cells(row, 4) = "Years" Then
bot.FindElementById("age_year").Click
bot.FindElementByName("age").SendKeys (Sheet1.Cells(row, 5).Value)
Else
If Sheet1.Cells(row, 4) = "Months" Then
bot.FindElementById("age_month").Click
bot.FindElementByName("age").SendKeys (Sheet1.Cells(row, 5).Value)
Else
If Sheet1.Cells(row, 4) = "Days" Then
bot.FindElementById("age_day").Click
bot.FindElementByName("age").SendKeys (Sheet1.Cells(row, 5).Value)
End If
End If
End If
'#Mobile Number
bot.FindElementById("contact_number").SendKeys (Sheet1.Cells(row, 3).Value)
'#Gender
If Sheet1.Cells(row, 6) = "Male" Then
Set ListDD = bot.FindElementById("gender")
ListDD.AsSelect.SelectByText (Sheet1.Cells(row, 6).Value)
Else
If Sheet1.Cells(row, 6) = "Female" Then
Set ListDD = bot.FindElementById("gender")
ListDD.AsSelect.SelectByText (Sheet1.Cells(row, 6).Value)
Else
If Sheet1.Cells(row, 6) = "Transgender" Then
Set ListDD = bot.FindElementById("gender")
ListDD.AsSelect.SelectByText (Sheet1.Cells(row, 6).Value)
End If
End If
End If
End Sub
要处理 VBA 中的错误,您可以使用On Error Goto <Label>
或On Error Resume Next
对于On Error GoTo <Label>
如果运行时异常发生时执行控制转到<Label>
块,并从开始执行那里。
因为On Error Resume Next
它只是忽略异常并从下一行开始执行。乍一看,它可能看起来很愚蠢,因为它可能会导致一系列错误并导致不可预测的行为。然而,经过精心开发,它确实有自己的使用费用份额。
在这种特殊情况下On Error Goto <Label>
会更合适,它看起来像这样。
Sub Automate()
START: 'Labled code block indicating start of our execution
On Error GoTo ERROR_HANDLE:
'Your code
Sheet1.Cells(Row, 10).Value = "DONE" 'Change the column index according to your column of choice
Exit Sub 'Or Exit Function if it is inside a function
ERROR_HANDLE: 'Labled code block defining error handling behavior
bot.Refresh
bot.SwitchToAlert.Accept
Sheet1.Cells(Row, 10).Value = "NOT DONE" 'Change the column index according to your column of choice
'If you want to start again from start immediately from here uncomment next line. However this can potentially become an infinite loop.
'GoTo START
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句