使用VBA填写HTML输入。结果已填入输入,但将其视为空的

时间:2017-11-15 02:31:59

标签: html vba

我遇到过一个奇怪的问题。我正在为我的工作填写一个网站(不能分享),以便加快一些帐户搜索。我已经设法填写我需要的东西,但它仍然把它视为盒子是空的,即使它们现在已经填充了我选择的数据。

我目前使用的一种解决方法是浏览所有内容,出于某种原因可行,但我真的不想使用sendkeys。

我尝试将aEle.innerText更改为value和占位符但没有工作。

这是我正在使用的代码,现在它非常混乱,我使用的html不使用任何ID,所以我不得不遍历每个标记。任何输入将不胜感激。感谢

Dim fullAcct, acct, branch, daterange1, daterange2 As String
Dim objIE As InternetExplorer
Dim aEle As HTMLLinkElement
Dim y, branchInput, accountInput, dateInput As Integer 'integer variables used as counters

'split selected account# into strings
fullAcct = selection
branch = Left(fullAcct, 3)
acct = Mid(fullAcct, 5, 6)
daterange1 = Date
daterange2 = DateAdd("yyyy", -25, daterange1) 'max date range

Set objIE = New InternetExplorer
objIE.Visible = True
'navigate IE to this web page
objIE.Navigate "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.com"

Do While objIE.Busy = True Or objIE.ReadyState <> 4: DoEvents: Loop

'set the counter for the for each loop and indicators of what to update
y = 1
branchInput = 2 'brach input
accountInput = 3
dateInput = 5
'for each <a> element in the collection of objects with a tag name "input"
For Each aEle In objIE.Document.getElementsByTagName("input")

    '**tried using .value and .placerholder but innerText seemed to work the best
    If y = branchInput Then 'check for second input (branch)
        aEle.innerText = branch
     End If
    If y = accountInput Then 'check for third input (account#)
        aEle.innerText = acct
    End If
    If y = dateInput Then 'check for date input
        aEle.innerText = daterange2
    End If
   y = y + 1
Next

SendKeys "{TAB 10}" 'must be tabbed through for some reason or the data isnt read

Application.Wait (Now + TimeValue("0:00:01"))

End Sub

0 个答案:

没有答案