查找通过JavaScript函数传递的变量的值

时间:2017-02-02 18:34:23

标签: javascript vba

我对JavaScript不太熟悉 - 如果我的解释没有意义,请原谅我。我正在尝试执行一个使用我找不到的变量的JavaScript函数。以下是页面源代码中的JavaScript函数。

function viewObjectionLetter(letterId)
{
    objLetterWindow = window.open('viewObjectionLetter.do?filingId=12345678&letterId='+letterId+'&viewOnly='+isEditUpdateMode(),'objectionLetterWindow','scrollbars,resizable,height=500,width=960');
    return false;
}

源显示单击链接时会执行以下功能。

viewObjectionLetter('13579');return false;

在vba中

Call CurrentWindow.execScript("viewObjectionLetter('letterId')")

返回网页错误,网址没有显示letterId的值。如何从页面中找到该值以执行该功能?

谢谢。

编辑: 这是完整的源代码。

Sub loadSERFF()

Dim ie As New InternetExplorer
Dim user As String
Dim pass As String
Dim product_name As String
Dim project_number As String
Dim author_name As Variant
Dim btn As Variant
Dim objs As New Collection
Dim coTrack As New Collection
Dim respondBy As New Collection
Dim productName As New Collection

user = Range("A2").text
pass = Range("B2").text

'Set IE = InternetExplorer.Application
ie.Visible = True
ie.Navigate "https://login.serff.com/serff/signin.do"

Do
DoEvents
Loop Until ie.ReadyState = 4

'Must NOT already be logged into SERFF
Do
ie.Document.forms(0).all("userName").Value = user 
ie.Document.forms(0).all("password").Value = pass
ie.Document.forms(0).submit
Loop Until ie.ReadyState = 4

Call pageLoad (ie)

ie.Navigate "https://login.serff.com/serff/viewOpenFilings.do"

Call pageLoad(ie)

'Need to account for multiple pages of open filings *IMPORTANT*
Set objectionsTags = ie.Document.getElementsByTagName("td")

i = 1
For Each objection In objectionsTags
    If InStr(LCase(objection.innerHTML), "pending industry response") Then
        coTrack.Add (objectionsTags(i - 4).innerHTML)
        productName.Add (objectionsTags(i - 5).innerHTML)
        i = i + 1
    Else
        i = i + 1
    End If
Next objection

ie.Document.forms(0).all("trackingNumber").Value = coTrack(1)
Dim CurrentWindow As HTMLWindowProxy: Set CurrentWindow = ie.Document.parentWindow
Call CurrentWindow.execScript("performQuickSearch('company');")

Call pageLoad(ie)

Call CurrentWindow.execScript("updateTab('objections');")

Call pageLoad(ie)

Call CurrentWindow.execScript("viewObjectionLetter('letterId')")

Call pageLoad(ie)

End Sub

2 个答案:

答案 0 :(得分:1)

Call CurrentWindow.execScript("viewObjectionLetter('letterId')")

这将文字值“letterId”传递给函数,这不会让你到任何地方。您需要找到实际值并传递它。

您可以从页面源中提取它,但由于您没有显示任何HTML,因此很难建议如何执行此操作。

为什么不点击链接呢?

答案 1 :(得分:0)

谢谢蒂姆。

解决方案就像你说的那样简单,只需点击即可。

Set objectionLetter = ie.Document.getElementsByTagName("a")
For Each objButton In objectionLetter
If InStr(LCase(objButton.innerHTML), "pending company response") Then objButton.Click
Next objButton