简体   繁体   English

Excel Selenium VBA:关闭 Web Selenium 弹出警报

[英]Excel Selenium VBA: Dismiss Web Selenium Pop-Up Alert

Steps:脚步:

Base URL: https://rivcoview.rivcoacr.org/#/Property-Search基地 URL: https://rivcoview.rivcoacr.org/#/Property-Search

  1. Select the dropdown " Select 下拉“ 在此处输入图像描述 "
  2. Enter 609542017 in the Text Box在文本框中输入 609542017
  3. Click "GO" Button点击“开始”按钮

When I am automating the above single action with a list of numbers and a loop.当我使用数字列表和循环自动执行上述单个操作时。 This Popup Alert occurs when I run a loop of PIN Numbers through, automating the "GO" click, then scaping the output page results.当我运行 PIN 码循环,自动点击“GO”,然后转义 output 页面结果时,会出现此弹出警报。 I am trying to dismiss the resulting popup.我试图关闭由此产生的弹出窗口。

No doubt, they have it triggered by some java in the background that detects my automation.毫无疑问,他们在检测我的自动化的后台由某个 java 触发了它。 I have seen several python or java possible solution examples for my problem that I can not translate to Excel VBA with Selenium. So I need a pure EXCEL VBA Selenium Solution.我已经看到几个 python 或 java 可能的解决方案示例,我无法将其转换为 Excel VBA 和 Selenium。所以我需要一个纯 EXCEL 8814304828581837 解决方案

CSS Selector for "X" button on the pop-up **= "#surveyModal > div > div > div.modal-header > button"

Tried:试过:

MyBrowser.SwitchToAlert.Dismiss

Set CloseButton = MyBrowser.FindElementByCss("#surveyModal > div > div > div.modal-header > button").click

I am still happy to get suggestions on VBA Selenium PopUps, but I have solved my problem.我仍然很高兴获得有关 VBA Selenium PopUps 的建议,但我已经解决了我的问题。 My Issue ended up not being a pop-up problem.我的问题最终不是弹出问题。 The Element was in the DOM all along as a hidden object .该元素一直作为隐藏的 object在 DOM 中。 So the following code solved my problem:所以下面的代码解决了我的问题:

Set SurveyButton = MyBrowser.FindElementByCss("#surveyModal")设置 SurveyButton = MyBrowser.FindElementByCss("#surveyModal")

If MyBrowser.FindElementByCss("#surveyModal").IsDisplayed Then如果 MyBrowser.FindElementByCss("#surveyModal").IsDisplayed 那么

 SurveyButton.Click

Else别的

GoTo 600

End If万一

600 600

'******************************* '************************************

I would use this as an alternative to test if the object was created.我会用它作为替代方法来测试是否创建了 object。 However, since it was present but hidden all along, the code below won't work and will cause an error.但是,由于它一直存在但一直隐藏,因此下面的代码将无法运行并会导致错误。

Set SurveyButton = MyBrowser.FindElementByCss("#surveyModal")设置 SurveyButton = MyBrowser.FindElementByCss("#surveyModal")

If Not MyBrowser.IsElementPresent(By.Css("#surveyModal")) Then如果不是 MyBrowser.IsElementPresent(By.Css("#surveyModal")) 然后

  SurveyButton.Click

Else别的

  GoTo 600

End If万一

600 600

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

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