简体   繁体   English

在 VBA 中使用 Selenium 警报处理程序与 Chrome

[英]Using Selenium Alert Handler in VBA with Chrome

I've placed a serial number in a box and clicked the button, and a popup alert appears saying that serial number is not found, OK to continue.我已将序列号放入一个框中并单击按钮,然后会出现一个弹出警报,提示未找到序列号,确定以继续。

TagSerialBox.Clear        ' Clear the default text already in the box
On Error GoTo AlertHandler  ' Go here if serial number not found
TagSerialBox.SendKeys serial ' Enter the serial number into the box
 Dim ClickPreview As selenium.WebElement  ' This is the item displayed
 Set ClickPreview = Partssite.FindElementById("fetchlink")   ' Focus on the link
    ClickPreview.Click       ' Click the link


AlertHandler: 
    MsgBox "Serial# " & serial & " not found, need to re-enter"
driver.SwitchToAlert().Accept    ' Should send OK to the alert popup and continue.

This code works fine when the serial number is found, but when it isn't found, it goes to the Alert Handler as expected and当找到序列号时,这段代码工作正常,但当找不到时,它会按预期进入警报处理程序,

  • the MsgBox works fine MsgBox 工作正常
  • the execution fails on the "driver.SwitchToAlert().Accept" line with a Run-time error '424': Object required.在“driver.SwitchToAlert().Accept”行执行失败,并出现运行时错误“424”:需要 Object。 I can't figure out what to do from the Selenium documentation.我无法从 Selenium 文档中弄清楚该怎么做。 Can ayone help with this?有人可以帮忙吗? Thanks.谢谢。

[https://www.guru99.com/alert-popup-handling-selenium.html][1] Might give you hints what the issue is. [https://www.guru99.com/alert-popup-handling-selenium.html][1] 可能会给您提示问题所在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM