Selenium Webdriver VBA-新循环错误
晚安,
如果可能的话,我希望一些帮助。我将此代码放在一起,但是如果找不到页面项目,我将无法创建输出。我希望,如果他没有找到Intem,他会去下一行,因为我有很多数据要捕获,因此不会显示错误消息。
Dim drive As New Selenium.ChromeDriver
Dim ks As Selenium.Keys
Dim tempo As Integer
Set ks = New Selenium.Keys
site = "http://www.google.com"
Plan1.Select
tell = Range("A" & Rows.Count).End(xlUp).Row
Line = 4
drive.Start
drive.Get site
Do Until Cells(Linha, 1) = ""
For Line = 4 To tell
Number = Range("A" & Linha).Value
drive.SwitchToFrame drive.FindElementById("WIDGET_ID_4")
Set telephone = drive.FindElementByXPath("/html/body/.........")
Range("B" & Line).Value = telephone.Attribute("outerText")
drive.SwitchToDefaultContent
Next Linha
Loop
drive.Quit
MsgBox "Process Ok"
End Sub```
Goodnight
I would like some help if possible. I'm putting this code together, but I'm not able to create an output if it doesn't find the page item. I would like if he doesn't find the intem he would go to the next line, not displaying an error message as I have a lot of data to capture.
Dim drive As New Selenium.ChromeDriver
Dim ks As Selenium.Keys
Dim tempo As Integer
Set ks = New Selenium.Keys
site = "http://www.google.com"
Plan1.Select
tell = Range("A" & Rows.Count).End(xlUp).Row
Line = 4
drive.Start
drive.Get site
Do Until Cells(Linha, 1) = ""
For Line = 4 To tell
Number = Range("A" & Linha).Value
drive.SwitchToFrame drive.FindElementById("WIDGET_ID_4")
Set telephone = drive.FindElementByXPath("/html/body/.........")
Range("B" & Line).Value = telephone.Attribute("outerText")
drive.SwitchToDefaultContent
Next Linha
Loop
drive.Quit
MsgBox "Process Ok"
End Sub```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在循环中,测试是否找到“选项卡”,即如果不是 tab 是什么都不做的。将设定线包装在一个错误简历中,下一个错误goto 0对,以抑制未发现异常的潜在元素。
我认为Linha应该是行,并使用数字来设置下一个ID。
请注意,使用不合格的范围,例如,没有指定工作表,您隐含地引用了当前的ActiveSheet,这是易于错误的。
Within the loop, test if the tab is found i.e. if not tab is nothing then do stuff.....else move to next id. Wrap the SET line in an On Error Resume Next On Error GoTo 0 pair to suppress potential element not found exception.
I think linha should be line and Number be used to set the next id.
Please do note that using unqualified ranges e.g. Range without specifying the worksheet, you are implicitly referencing the current ActiveSheet and this is bug-prone.