简体   繁体   English

VBA和Selenium如何处理弹窗?

[英]How to handle webpage pop-up with VBA and Selenium?

I have a problem with a code that I am developing in VBA. I am trying to access a web page through the Excel macro.我在 VBA 中开发的代码有问题。我试图通过 Excel 宏访问 web 页面。 This web page is to access a camera connected to my.network, due to its brand (Axis), when accessing I have to enter the username and password, and these text boxes appear in a pop-up window. I am using Google Chrome and the Selenium library.这个 web 页面是访问连接到 my.network 的相机,由于它的品牌(Axis),访问时我必须输入用户名和密码,并且这些文本框出现在弹出窗口 window。我使用的是 Google Chrome和 Selenium 图书馆。

I have no way of finding out their "id" by pressing F12 or by right clicking and pressing "Inspect element" as can be done on the website itself.我无法通过按 F12 或右键单击并按“检查元素”来找出它们的“ID”,就像在网站本身上可以完成的那样。 Finding out their "id" could handle them.找出他们的“身份”可以解决他们。 It seems that handling pop-up windows is more complicated.看来处理弹窗windows比较复杂。 I found some information about this, but it didn't help me much.我找到了一些有关此的信息,但对我没有太大帮助。

For now I can open Google Chrome and access the website, but I cannot enter data in this window. I have tried several Selenium functions, such as writing on the active element, but I don't give any results.现在我可以打开谷歌浏览器并访问该网站,但我无法在这个window中输入数据。我尝试了几个Selenium功能,例如在活动元素上写字,但我没有给出任何结果。 Any information on this would help me a lot.关于这方面的任何信息都会对我有很大帮助。

These are my few lines of functional code and a image of the pop-up window:这些是我的几行功能代码和弹出窗口 window 的图像:

Public Sub OpenUrl()

Dim obj As New WebDriver

obj.Start "chrome", ""
obj.Get ("webpage")

End Sub

弹出窗口

Use application.sendkeys to interact with the pop up window box.使用 application.sendkeys 与弹出的 window 框进行交互。 Use this website to learn more what steps you are able to complete:使用此网站了解更多您能够完成的步骤:

https://learn.microsoft.com/en-us/office/vba/api/excel.application.sendkeys https://learn.microsoft.com/en-us/office/vba/api/excel.application.sendkeys

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

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