0

I am trying to select the value from a dropdown box using vba, the code block for the dropdown box is as follows

<input type="text" id="form_autocomplete_input-1542902425322" list="form_autocomplete_suggestions-1542902425322" placeholder="Search keyword or select filter" role="combobox" aria-expanded="false" autocomplete="off" autocorrect="off" autocapitalize="off" aria-autocomplete="list" aria-owns="form_autocomplete_suggestions-1542902425322 form_autocomplete_selection-1542902425322">

If the value of form_autocomplete_suggestions-1542902425322 was static I would use .Document.getElementById("form_autocomplete_suggestions-1542902425322").Value = "Role: Student" however this seems to be a randomly generated numerical value.

I have had a look and it seems I cannot simply add a wildcard in such as .Document.getElementById("form_autocomplete_suggestions-*").Value = "Role: Student"

And as its randomly generated and such a long number it cannot loop through an array of values. so I am unsure on how to solve this issue.

2
  • So how many text boxes will there be on the form? You dont have to loop through the array of numbers, you can look at the options on offer beginning with .getElements etc, to get them to a collection and loop those if neccessary. Can you explain a little more in numbers of objects, or paste a screen shot of the page.? Commented Nov 22, 2018 at 16:29
  • Hi, not sure what you mean by form? the problem is that the value of the dropdown box changes !image So I cannot use .Document.getElementById("form_autocomplete_suggestions-1542902425322").Value = "Role: Student" as the value of 1542902425322 has now changed to something else. Commented Nov 22, 2018 at 16:57

1 Answer 1

1

You can use css attribute equals value selector syntax with the ^ operator to say starts with a certain substring. You could also use * instead, which means contains.

[id^='form_autocomplete_input-']

VBA:

ie.document.querySelector("[id^='form_autocomplete_input-']")

You might also use:

[placeholder='Search keyword or select filter']

Which would be:

ie.document.querySelector("[placeholder='Search keyword or select filter']")

As you indicate this needs to be selected you may need:

ie.document.querySelector("[id^='form_autocomplete_input-']").Selected = True

Reference:

  1. CSS attribute selectors
Sign up to request clarification or add additional context in comments.

1 Comment

Did you try this?

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.