简体   繁体   English

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

[英]Finding the value of a variable passed through a JavaScript function

I am not very familiar with JavaScript - please forgive me if I my explanation does not make sense.我对 JavaScript 不是很熟悉 - 如果我的解释没有意义,请原谅我。 I am trying to execute a JavaScript function that is using a variable that I can't find.我正在尝试执行一个使用我找不到的变量的 JavaScript 函数。 Below is the JavaScript function in the page source.下面是页面源代码中的 JavaScript 函数。

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

The source shows that when the link is clicked it executes the following function.来源显示,当点击链接时,它会执行以下功能。

viewObjectionLetter('13579');return false;

In vba在 vba 中

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

returns a webpage error and the url shows no value for letterId.返回网页错误,并且 url 没有显示 letterId 的值。 How can I find that value from the page in order to execute the function?如何从页面中找到该值以执行该函数?

Thank you.谢谢你。

Edit: Here is the complete source code.编辑:这是完整的源代码。

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
Call CurrentWindow.execScript("viewObjectionLetter('letterId')")

This passes the literal value "letterId" to the function, which isn't going to get you anywhere.这会将字面值“letterId”传递给函数,这不会让您到任何地方。 You need to find the actual value and pass that.您需要找到实际值并传递它。

You can extract that from the page source, but since you don't show any HTML it's difficult to suggest how to do that.您可以从页面源代码中提取它,但由于您没有显示任何 HTML,因此很难建议如何执行此操作。

Why not just click the link though?为什么不直接点击链接呢?

Thank you Tim.谢谢蒂姆。

The solution was as simple as you said, just click it.解决方法就像你说的一样简单,点击它即可。

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

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

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