我有一个密码;
#Same code in Python
try:
io = myElm.get_attribute("rel")
print(io)
except IndexError:
d_io = myElm.get_attribute("data-outcome")
print(d_io)
except:
print("undefined error")
我在和硒一起工作。当我搜索它时,互联网上说没有尝试-cath或尝试-期待的方法VBA。您可以在错误GoTo中使用mehtod。
我的目的是,有一个元素。有时它没有"rel“属性,并且返回一个错误。因此,如果存在"rel“属性。如果没有,我将接受它,我将使用“数据-结果”属性。上面的代码在python中工作得很好。
我可以通过在互联网上的研究来转换代码如下。
唯一的问题是,当我使用GoTo语句时。我不能回到我离开的地方。我试过了,就像简历下 smh一样。它不起作用。也许我做不到。顺便说一句,我只是用于一个应用程序,只是一个VBA上的新手。是否有方法在使用GoTo方法后返回。因为我不能返回,所以当我转到goto语句时,用"rel“属性创建的值会发生变化。总之,我基本上有三个陈述,如;
On Error GoTo C1
If baglan.IsElementPresent(By.Css(myElm)) Then
Cells(sonsatir, 4) = baglan.FindElementByCss(myElm).Attribute("rel")
Else
Cells(sonsatir, 4) = baglan.FindElementByCss(myElm).Attribute("data-outcome")
End If
On Error GoTo C2
If baglan.IsElementPresent(By.Css(myElm)) Then
Cells(sonsatir, 5) = baglan.FindElementByCss(myElm).Attribute("rel")
Else
Cells(sonsatir, 5) = baglan.FindElementByCss(myElm).Attribute("data-outcome")
End If
On Error GoTo C3
If baglan.IsElementPresent(By.Css(myElm)) Then
Cells(sonsatir, 6) = baglan.FindElementByCss(myElm).Attribute("rel")
Else
Cells(sonsatir, 6) = baglan.FindElementByCss(myElm).Attribute("data-outcome")
End If
'Some codes here'
C1:
Cells(sonsatir, 4) = baglan.FindElementByCss(myElm).Attribute("data-outcome")
C2:
Cells(sonsatir, 5) = baglan.FindElementByCss(myElm).Attribute("data-outcome")
C3:
Cells(sonsatir, 6) = baglan.FindElementByCss(myElm).Attribute("data-outcome")
发布于 2021-08-04 14:52:09
只使用Resume
而不是Resume Next
。
Resume
返回错误发生的地方。
错误发生后,Resume Next
跳转到下一行。
https://stackoverflow.com/questions/62180254
复制相似问题