处理例外的正确方法>点击按钮>的webdriver?
我的代码:
Private WithEvents visioApplication As Microsoft.Office.Interop.Visio.Application
Private beginQueuedEvent As Integer
Private endQueuedEvent As Integer
Private betweenMarker As Boolean
Public Sub UseMarker(ByVal markedPage As Microsoft.Office.Interop.Visio.Page)
' Get the Application object of the currently running Visio application.
visioApplication = CType(markedPage.Application, Microsoft.Office.Interop.Visio.Application)
Try
betweenMarker = False
beginQueuedEvent = visioApplication.QueueMarkerEvent("Shape is changed")
Catch err As System.Runtime.InteropServices.COMException
System.Diagnostics.Debug.WriteLine(err.Message)
End Try
End Sub
Private Sub applicationMarkerEventHandler(ByVal theApplication As Microsoft.Office.Interop.Visio.Application, ByVal sequenceNumber As Integer, ByVal context As String) Handles visioApplication.MarkerEvent
Try
' Ignore marker events with no context string
If Not IsNothing(context) Then
If context.Length() <> 0 Then
' If the value of sequenceNumber is either beginQueuedEvent or
' endQueuedEvent, the event results from the calls to the
' QueueMarkerEvent method.
' Note: betweenMarker is used in the
' shapeAddedToPageEventHandler to process the ShapeAdded
' messages fired between the two QueueMarkerEvent calls.
If (sequenceNumber = beginQueuedEvent) Then
betweenMarker = True
End If
End If
End If
Catch err As System.Runtime.InteropServices.COMException
System.Diagnostics.Debug.WriteLine(err.Message)
End Try
End Sub
Private Sub shapeAddedToPageEventHandler(ByVal addedShape As Microsoft.Office.Interop.Visio.Shape) Handles visioApplication.CellChanged
Dim dA As Double 'Area value
Dim dP As Double 'Perimeter value
Dim sName As String 'Shape name
Dim xPS As Visio.Shape 'Visio Shape
Try
If (betweenMarker) Then
xPS = Application.ActiveWindow.Selection.PrimaryItem
If InStr(xPS.Name, ".") > 0 Then
sName = Left(xPS.Name, InStr(xPS.Name, ".") - 1)
Else
sName = xPS.Name
End If
Select Case sName
Case "My Area"
dA = xPS.AreaIU
dP = xPS.LengthIU
xPS.Cells("User.Area").FormulaForceU = dA
xPS.Cells("User.Perimeter").FormulaForceU = dP
End Select
End If
Catch err As System.Runtime.InteropServices.COMException
System.Diagnostics.Debug.WriteLine(err.Message)
End Try
End Sub
答案 0 :(得分:3)
我个人喜欢让错误冒出来。在这种情况下,如果您尝试与元素交互(例如单击链接),则在交互出现问题时将引发硒异常。例如,它可能会抛出陈旧的元素异常或未找到元素异常,具体取决于问题所在。在我看来,如果你添加这个try catch块,你实际上不会知道真正的问题是什么。
我建议尽可能保留默认的异常映射。