1

Currently I'm making a bot which ultimately should simply play a song on a website, but the bot simply is unable to click the button. I aquired the name of the button by inspecting the HTML code on the website. I will show my code below and also add a picture which shows what might be wrong with my code:

set webbrowser = createobject("internetexplorer.application")
webbrowser.statusbar = false
webbrowser.toolbar = false
webbrowser.menubar = false
webbrowser.visible = true

webbrowser.navigate("https://skiomusic.com/gravit/noah-kahan-hurt-somebody-gravi-t-remix")

WScript.sleep(8000)

webbrowser.document.all.item("div.playBtn").click

WScript.sleep(10000)

webbrowser.Quit

Line 11, character: 1, error: object required, source: microsoft runtime error

My question is obviously, how do I fix this error?

Gravi
  • 11
  • 2
  • What is `div.playBtn` supposed to be? A `
    ` tag with the CSS class `playBtn`? That can't be selected like that. You need to select the `
    ` elements and check their `class` attribute. You may also try `getElementsByClassName()`, but in my experience that usually fails. I'm not quite sure under which circumstances it works and which prevent it from working.
    – Ansgar Wiechers Jul 10 '18 at 19:50
  • @AnsgarWiechers I'm going to be honest, I don't quite understand your comment, but if you'd like to help me out; the site of which I'm trying to click the play button with my code is the following: https://skiomusic.com/gravit/noah-kahan-hurt-somebody-gravi-t-remix – Gravi Jul 10 '18 at 20:03

1 Answers1

0

Well.. it seems you did not inspect the HTML code well enough. div.playBtn means nothing. I've looked at the page and saw the button does not have an id, but it does have a class by name of playBtn. In order to find this object, you should use the getElementsByClassName function wich returns a collection. From that collection you want the first item.

Try this

Option Explicit

Dim webbrowser, button
Set webbrowser = createobject("internetexplorer.application")
webbrowser.statusbar = False
webbrowser.toolbar   = False
webbrowser.menubar   = False
webbrowser.visible   = True

webbrowser.navigate("https://skiomusic.com/gravit/noah-kahan-hurt-somebody-gravi-t-remix")

WScript.sleep(8000)  ' why wait so long??

Set button = webbrowser.Document.getElementsByClassName("playBtn").Item(0)
button.Click

WScript.sleep(10000)

webbrowser.Quit
Theo
  • 57,719
  • 8
  • 24
  • 41
  • come to think of it... It may be better to use `Do While webbrowser.Busy Or webbrowser.ReadyState <> 4: WScript.Sleep 100: Loop` instead of `WScript.sleep(8000)`. Just a thought.. – Theo Jul 15 '18 at 19:03