对象是必需的,但对象确实存在

时间:2019-04-13 03:25:16

标签: vbscript

这工作了好几次,我把它给了我的朋友,他开始在第68行出现错误。需要对象。

Line:68
Char: 2
Error: Object required: 'document.all.item(...)'
Code: 800a01a8
Source: VBScript runtime error

需要一个网站来请求请求中的歌曲和垃圾邮件。我有权这样做。该错误并未发生,但现在已经发生。 Visual Studio完全是最新的。我在Windows 10上。它确实可以工作,但是现在抛出该错误。

我已经尝试过更新Windows和Visual Studio。同样在命令提示符下运行它不会产生任何信息。

Option Explicit

Dim browser,x,loginpass,datem,dated,datey,nameArr,numberOfRequests,artistName,songName

set x = CreateObject("wscript.shell")
'Random init shit'
loginpass = "space"
datem = 5
dated = 4
datey = 2019
'Fill this array with names, and it will loop through all of them when you run it.'
nameArr = Array("Becka","Kelly","Jake","Joseph")
'This will control how many times the selected song is voted for'
numberOfRequests = 5
'What is your song pick?'
artistName = "PinkFong"
songName = "Baby Shark"


Dim ree
ree=msgbox("You selected " & songName & " by " & artistName & ". If that is not correct, click no.", 4096+64+4, "Reeee, make sure you don't request the wrong shitty song!")
If ree = vbNo Then
    WScript.Quit
End If  


Dim name
For Each name in nameArr 'name loop'
    'initialize the browser in the most basic form'
    set browser = createobject("internetexplorer.application")
    browser.statusbar = false
    browser.menubar = false
    browser.toolbar = false
    browser.Width = 1360
    browser.Height = 768
    browser.top = 100
    browser.Left = 100
    browser.Resizable = 0
    browser.visible = true

    'navigate to the login website with the specified djidnumber'
    x.AppActivate "Internet Explorer"
    browser.navigate([sitenameredacted])
    do while browser.busy
        wscript.sleep(100)
    loop

    'input the date and password into the fields provided'
    browser.document.all.item("password").value = loginpass
    browser.document.all.item("month").value = datem
    browser.document.all.item("day").value = dated
    browser.document.all.item("year").value = datey
    wscript.sleep(500) 'This is line 61'
    x.SendKeys "{ENTER}"
    do while browser.busy
        wscript.sleep(100)
    loop

    'Deal with the guestname dialogue befor looping song pick 10 times.'
    browser.document.all.item("guest_name").Click() 'this is the line 68 in question'
    wscript.sleep(500)
    Set x = CreateObject("wscript.shell")
    x.SendKeys name
    wscript.sleep(100)
    x.SendKeys "{ENTER}"
    wscript.sleep(100)

    'Select the button for add your own.'
    browser.Document.getElementByID("addyourown_a").click
    wscript.sleep(100)

    'Loop the song request the number of times given'
    Dim loops
    For loops = 1 to numberOfRequests
        browser.Document.getElementByID("add_your_own_artist_name_id").value = artistName
        browser.Document.getElementByID("add_your_own_song_title_id").value = songName
        For Each btn In browser.Document.getElementsByTagName("input")
            If btn.value = "Save" Then btn.Click()
        Next
        wscript.sleep(100)
    Next

    'Submit requests and then close browser for the next name to start.'
    For Each btn In browser.Document.getElementsByClassName("djep-guestsubmit")
            If btn.href = "javascript:document.ep_form.submit();" Then btn.Click()
    Next

    wscript.sleep(5000)
    browser.Quit

 Next 'name loop'

我希望它可以在网站上设置登录信息,然后登录。然后,它在列表中输入名字并确认对话。然后,建议同一首歌曲5次。当我将其分离时,这种方法可以完美地工作。

当我向61行添加5秒等待时间而不是0.5秒等待时间时,什么都没有改变,因此我认为错误在61行以上。

1 个答案:

答案 0 :(得分:0)

我实际上已解决此问题。问题是x.SendKeys {ENTER}

Enter并没有真正推进对话,因此它正在寻找尚不存在的元素guest_name