Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Excel VBA登录网站_Javascript_Html_Vba_Internet Explorer_Excel - Fatal编程技术网

Javascript 使用Excel VBA登录网站

Javascript 使用Excel VBA登录网站,javascript,html,vba,internet-explorer,excel,Javascript,Html,Vba,Internet Explorer,Excel,谢谢你看这个问题。我正试图通过VBA登录到一个网站。这可能已经得到了回答,但我很难找到有效的方法。我以前用VBA做过互联网自动化。我以前甚至用它登录过不同的网站,但这一次给了我一个问题。我尝试过getElementByID、getElementByTagName等,但似乎没有任何东西能够填充“loginName”和“password”文本框 该网站是 我发现奇怪的是,当我通过谷歌浏览器检查一个元素时,它不会带我去我选择的文本框 非常感谢。很抱歉,我对VBA还是一个新手,这是我第一次在这个网站上发

谢谢你看这个问题。我正试图通过VBA登录到一个网站。这可能已经得到了回答,但我很难找到有效的方法。我以前用VBA做过互联网自动化。我以前甚至用它登录过不同的网站,但这一次给了我一个问题。我尝试过getElementByID、getElementByTagName等,但似乎没有任何东西能够填充“loginName”和“password”文本框

该网站是

我发现奇怪的是,当我通过谷歌浏览器检查一个元素时,它不会带我去我选择的文本框

非常感谢。很抱歉,我对VBA还是一个新手,这是我第一次在这个网站上发表文章

我现在拥有的代码如下:

Sub FVFO()
Dim IE As InternetExplorerMedium
Dim uRl As String
Dim UserN As Object 'MSHTML.IHTMLElement
Dim PW As Object 'MSHTML.IHTMLElement

Set IE = New InternetExplorerMedium

uRl = "https://vfo.frontier.com/"

With IE
    .navigate uRl
    .Visible = True

End With

 ' loop until the page finishes loading
Do While IE.Busy
Loop
' enter username and password in textboxes
Set UserN = IE.document.getElementsByName("loginName")
If Not UserN Is Nothing Then
    ' fill in first element named "username", assumed to be the login name field
    UserN.Value = "login name"
End If
Set PW = IE.document.getElementsByName("password")
' password
If Not PW Is Nothing Then
    ' fill in first element named "password", assumed to be the password field
    PW.Value = "my Password"
End If

End Sub

GetElementsByName
返回元素的集合——即使只有一个元素,它仍然是一个集合。因此,您需要对其进行正确的索引。假设该元素名称的第一个实例是适当的:

UserN(0).Value = "login name"
同样地:

PW(0).Value = "my password"
结果:

InternetExplorer.Application
(我不知道什么是InternetExplorerMedium…)中使用后期绑定进行测试(尽管这不重要):

以下也可以使用
getElementByID
方法工作,该方法返回单个元素(因为
id
是唯一的):


回答得好,大卫。信息量很大。我添加了索引,一切正常,不过我不得不切换到InternetExplorer.Application。我之所以使用InternetExplorerMedium,是因为我以前一直在公司内部网上工作,出于某种原因,这是唯一有效的方法。我必须进一步研究每种方法的属性。再次感谢!
Dim IE as Object
Set IE = CreateObject("InternetExplorer.Application")
Set UserN = IE.document.getElementByID("loginName")
If Not UserN Is Nothing Then
    ' fill in first element named "username", assumed to be the login name field
    UserN.Value = "blargh"
End If
Set PW = IE.document.getElementByID("password")
' password
If Not PW Is Nothing Then
    ' fill in first element named "password", assumed to be the password field
    PW.Value = "my Password"
End If