使用JavaScript从控制台运行ng-click功能

时间:2017-10-24 11:54:14

标签: javascript angularjs

我使用以下代码(不是我的)在页面上构建交互:

<a id="refreshDataAction" href="#" class="Action Edit ng-scope ng-isolate-scope Tipsified" #some other code here#>
<span class="Tipsified" data-original-title="Get delivery ids from Box<br> #some other code here# ng-click="refresh()">

我需要以某种方式激活这个&#34; refresh()&#34;通过单击按钮或直接寻址函数来形成ng-click的函数。

Standart approcach .GetElimentById("x").Click不起作用。

我发现一些解决方案可以在$ like here范围内使用,但它们看起来更像是在页面代码本身内部使用,而我更需要一种单行方法来直接从控制台运行它(或者,实际上,使用".execScript("x", "JavaScript"))从VBA寻址

2 个答案:

答案 0 :(得分:0)

运行vanilla click回调时,

ng-click 不会触发,因为它是Angular操作属性。除了你的HTML格式不正确(我不知道它是否有意),你可以试试这个:

<span id="_some_id" class="Tipsified" onclick="refresh()">

然后:

getElementById("_some_id").click();

答案 1 :(得分:0)

在VBA上我们需要输入索引号,你可以试试。

Set elem = ie.Document.getElementById("_some_id")(0)

elem.Click

Set elems = ie.Document.getElementById("_some_id")

For Each e In elems
    If (e.innerText = " The One") Then
        e.Click
        Exit For
    End If
Next e