【发布时间】:2016-10-03 21:59:06
【问题描述】:
我卡住了,在 VBA 中我想访问使用 AngularJS 的页面上的 HTML 元素,
所有这些元素“存在”,因为我在使用 IE 调试器工具时看到了它们。它们都在一个名为“cont”的父 div 中。
问题:
当我查看网站的源代码时,这个 div 是空的。我只能看到结构,即:
<div
class="cont"
data-ng-controller=".."
..
data-ng-init="initApplication()">
</div>
但里面什么都没有。它可能是在 angular 之后加载的。
因此,当我尝试访问此 div 内的按钮时,例如:
Set IE = CreateObject("InternetExplorer.Application")
IE.document.getElementsById("submitBtn").click
然后我收到一条错误消息,指出该对象不存在..
所以我尝试在之前添加:
' wait until IE and the page are ready
Do While .Busy Or Not .readyState = 4: DoEvents: Loop
' wait until the DOM is ready
Do Until .document.readyState = "complete": DoEvents: Loop
但是没有任何效果,我完全不明白,是否可以访问此 div 中的 HTML 元素?为什么我在调试器工具中看到 evthg?
有什么想法吗??
更新
我发现 div 的内容位于一个 .js 文件中,那里有数百万个东西但是有:
angular.module("cont").factory("applicationService",["$rootScope","ngDialog","webService",
function(a,b,c){
"use strict";
var d={},
e="home";
d.initApplication=function(){
return c.initContact()
}
还有:
angular.module("cont").run(["$templateCache",function(a){"use strict";
a.put("Application",'ALL THE CONTENT IS HERE (with an HTLM element I would like to click)!!!!!'
【问题讨论】:
-
您需要展示更多现有代码 - 这两行并没有告诉我们太多信息。如果元素出现在 Ceveloper 工具源中,那么您应该能够访问它。还要注意
getElementsById应该是getElementById(没有“s”) -
您的按钮在框架中吗?您是否在浏览器的控制台中得到
document.getElementsById("submitBtn")的结果? -
没有不在框架中,我在控制台中得到 null
-
@Julient And with
document.getElementById("submitBtn")without an "s" ordocument.querySelector("#submitBtn")?
标签: javascript html angularjs vba automation