shahin
Active Member
Hi there!! I've written a script which is able to surf a webpage ,put certain values in two dropdown boxes, click on the search button and produce valid results. As I've never worked with dropdown selection programmatically, I don't understand the proper way to deal with it. What I've done so far is input two hardcoded values in two respective search boxes and produced the search results. How can I do the same using dropdown option and not obviously with hardcoded values?
Here is the script I've tried so far with:
Btw, the link of that webpage is already available in my script. The two dropdown boxes can be seen if you press the two images attached below. I've already marked with pencil to let you know the two search (dropdown) fields. Search input can be anything but that should be selected from the dropdown option. I've uploaded the second image only to show that how a dropdown box looks like when it is selected. Thanks in advance.
Here is the script I've tried so far with:
Code:
Sub Dropdown_Items()
Dim IE As New InternetExplorer, html As HTMLDocument
Dim posts As Object, post As Object, elem As Object
With IE
.Visible = True
.navigate "https://www.sptv.ch/trainersuche"
Do Until .readyState = READYSTATE_COMPLETE: Loop
Set html = .document
End With
Application.Wait (Now() + TimeValue("00:00:005"))
For Each post In html.getElementsByTagName("input")
If InStr(post.Value, "Einsatzbereiche") > 0 Then post.Value = "Golf"
Next post
For Each posts In html.getElementsByTagName("input")
If InStr(posts.Value, "Region") > 0 Then posts.Value = "Bern"
Next posts
For Each elem In html.getElementsByTagName("input")
If InStr(elem.Value, "Suchen") > 0 Then elem.Click
Next elem
Application.Wait (Now() + TimeValue("00:00:005"))
IE.Quit
End Sub
Btw, the link of that webpage is already available in my script. The two dropdown boxes can be seen if you press the two images attached below. I've already marked with pencil to let you know the two search (dropdown) fields. Search input can be anything but that should be selected from the dropdown option. I've uploaded the second image only to show that how a dropdown box looks like when it is selected. Thanks in advance.
Attachments
Last edited: