Results 1 to 2 of 2

Thread: trouble changing value of an input box on a website with vba

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Posts
    12

    trouble changing value of an input box on a website with vba

    I'm having an issue attempting to manipulate a website with vba. It is a secure website so I cant post it. I need suggestions i can test or if someone can explain what i'm missing.

    so far i can open the website & login, no issue & i can click the button to navigate to the search screen, here i hit the wall. all i need to do is fill in a text box (then hit search). when i inspect the element on the text box I get:

    however, it seems it's really a control group. this code:
    Set HTMLInputs = HTMLDoc.getElementsByClassName
    For Each HTMLInput In HTMLInputs
    Debug.Print "ClassName:" & HTMLInput.className, "TagName:" & HTMLInput.tagName, "ID:" & HTMLInput.Id, "InnerText:" & LTrim(HTMLInput.innerText)
    If InStr(HTMLInput.innerText, "Policy") > 0 Then
    HTMLInput.value = "9509966270"
    Exit For
    End If
    Next HTMLInput

    looped successfully & found the field (i thought) but i cannot input into the text box. is it possible to tell what the item is that i'm looping thru in the elements collection? maybe i'm hitting a label not a text box. is it possible that its connected to the text box i want (it is the right text, just above it on the web page. i also saw something on using setattribute on an aria. any advice appreciated! thank you!
    -Jim

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: trouble changing value of an input box on a website with vba

    Code:
    Set HTMLInputs = HTMLDoc.getElementsByClassName
    For Each HTMLInput In HTMLInputs
    Debug.Print "ClassName:" & HTMLInput.className, "TagName:" & HTMLInput.tagName, "ID:" & HTMLInput.Id, "InnerText:" & LTrim(HTMLInput.innerText)
    If InStr(HTMLInput.innerText, "Policy") > 0 Then
    HTMLInput.value = "9509966270"
    Exit For
    End If
    Next HTMLInput
    This line If InStr(HTMLInput.innerText, "Policy") > 0 Then only looks for the word Policy in the text.
    If it is an input (search) textbox it could have any text in it?.

    If the 'secure' site doesnt change the id of the control, look for a match on that. If it does change, then you'd be checking all controls for a combination, such as the label with x text appears, the next control that is an input will be the one you want.
    Code for that might be something like
    Code:
    set boolean foundLabel to false
    loop controls
    --- if foundLabel is true and control type is input/textbox then insert text x
    --- if control type is label and text has 'policy' then set boolean foundLabel to true
    All depends on the site you are trying to access.

    Which only you and the developers know.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width