1

My issue is attempting to interact with a website using VBA.

I have dealt with filling in input boxes by simply saying ie.document.getElementById(strId).value = my_value as well as when those elements exist inside of a form.

But for the life of me I cannot get this to work. I will post as much of the HTML as I can.

HTML:

<input title="Order Number" class="mtn-srch-text text-field req" id="orderNum" type="text" maxLength="10" data-sticky-placeholder="Order Number">

VBA that is attempting to take the orderNum field and fill it in.

 objBrowser.document.getElementById("orderNum").value = "1234"

Object Required error each time, so I am thinking its not looking in the right spot as the element surely exists, but I am incorrectly pointing to it. Since I do not see any form tags in the HTML on this page, I did not know how to proceed to drill down to get this input box filled. Any advice would be awesome!

Adding some more of the code, had to remove a few of the URLS and username/pass but as you can see navigating is very simply until we get to the iFrames part of it. Which I now see each iFrame has a differebt SRC which is probably why

 .contentDocument.getelementbyId("textbox").value = "test" 

wont work. What we are focused on is everything below the dotted line, as you can see its just me toying around stepping through an attempting different things.

   Dim strPosUrl As String, strUsername As String, strPassword As String, _
       strStoreDomId As String, strStore As String, _
       strBtnStoreUpdateDomId As String, strOrder As String, _
       strLoadingSpinner As String, strCssAttributeSpinner As String, _
       strCssTextSpinner As String
    Dim objBrowser As Object 'SHDocVw.InternetExplorer
    Dim blnSsoLogin As Boolean
    Dim intStoreColNum As Integer, intOrderColNum As Integer, _
        intCreditCardColNum As Integer
    'Dim doc As MSHTML.HTMLDocument

            'these are test vars-----------------
            strStore = "Data"
            strOrder = "Data"
            '----------------------------------
            strLoadingSpinner = "spinnerUnique"
            strCssAttributeSpinner = "style"
            strCssTextSpinner = "display: none;"

            strUsername = "example"
            strPassword = "EXample"
            strStoreDomId = "orderLocInputId"
            strBtnStoreUpdateDomId = "orderLocValueUpdate"
            strPosUrl = "https://example.jsp"

            Set objBrowser = New InternetExplorerMedium
            objBrowser.Visible = True
            browserNavigate strPosUrl, objBrowser
            browserWait objBrowser
            blnSsoLogin = ssoLoginCheck(objBrowser)

            Select Case blnSsoLogin

                    Case Is = True
                            ssoLoginMod strUsername, strPassword, objBrowser
                            browserWait objBrowser
                    Case Is = False

            End Select

            fillTextboxWithId objBrowser, strStoreDomId, strStore
            clickButtonWithId objBrowser, strBtnStoreUpdateDomId
            browserWait objBrowser

            foundOrNot strLoadingSpinner, strCssAttributeSpinner, _
                       strCssTextSpinner, objBrowser



'-----------------------------------------------------
            Dim IFrameText As Object
            Set IFrameText = objBrowser.document.getElementById("frmHome")
            IFrameText.HTML.getElementById("ordernum").Value = "1223"

            Dim x As String
            objBrowser.navigate "https://xxxxxxx.xxxxxxx.com" & x
            x = objBrowser.LocationURL

            x = "just messing with stuff"

            Set IFrameText = objBrowser.document.getElementById("frmHome")
            Dim elem As Object
           For Each elem In IFrameText
                If elem.innerText Like "*true*" Then
                MsgBox (elem)
                End If
                Next
9
  • Is the input in a frame? If you put a break just before you try to access the element and wait a couple of seconds before continuing does it then work? Commented Oct 25, 2017 at 3:26
  • Hi, I think I see where you are going. I have gotten pretty good about making sure items I require on a page are all loaded before I try to access anything. But I did attempt what you said, but no luck, same thing. Commented Oct 27, 2017 at 13:10
  • Id like to note I use the java script spinner css text to let me know when a page is done loading, I find this works great for pages that are running scripts even after IE stops loading. Commented Oct 27, 2017 at 13:11
  • Can't really offer any more suggestions without a URL. Commented Oct 27, 2017 at 14:54
  • Unfortunately, you would not be able to access the URL. What I can do is show this. Commented Oct 27, 2017 at 15:28

1 Answer 1

2

It was in a table.

So its really simple:

getelementbyid("yourTableId").getElementsByTagName("tr")(x row).getElementsByTagName("td")(x cell)

After that, do what you want with the element.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.