【发布时间】:2021-10-28 02:39:44
【问题描述】:
大家好,我正在尝试关注https://www.youtube.com/watch?v=Wn9L1MD_y0Y&t=107s,了解如何使用 VBA 自动化 whatsapp。
这是整个代码。
Sub WebWhatsApp()
'Activate Selenium Type Library: Tools > Reference
Dim bot As New WebDriver
Dim ks As New Keys
'Init New Chrome instance & navigate to WebWhatsApp
bot.Start "chrome", "http://web.whatsapp.com/"
bot.Get "/"
'Ask user to scan the QR code. Once logged in, continue with macro
MsgBox "Please scan the QR code. After you are logged in, please confirm this message box by clicking"
'Determinate number of messages by identifying the number of last rows in column A
lastrow = Cells(Rows.Count, 1).End(x1Up).Row
'Search phonenumber/name, press enter, paste text into WebWhatsApp, press Enter to send message
For i = 2 To lastrow
'Get search text (phone number or name) from worksheet
searchtext = Sheets(1).Range("A" & i).Value
'Get textmessage from worksheet
textmessage = Sheets(1).Range("B" & i).Value
'click in the searchbox"
bot.FindElementByXPath("//*[@id="side"]/div[1]/div/label/div/div[2]").Click
'Wait 500 ms
bot.Wait (500)
'Insert search text(phone number or name)
bot.SendKeys (searchtext)
'Wait 500 ms
bot.Wait (500)
'Press Enter to confirm search text
bot.SendKeys (ks.Enter)
'Wait 500 ms
bot.Wait (500)
'Load message into WebWhatsApp
bot.SendKeys (textmessage)
'Wait 500 ms
bot.Wait (500)
'Press Enter to send the message
bot.SendKeys (ks.Enter)
Next i
'Get notification once done,
MsgBox "Done :)"
End Sub
显然我遇到了错误
bot.FindElementByXPath("//*[@id="side"]/div[1]/div/label/div/div[2]").Click
它说明编译错误:语法错误
谁能告诉我为什么?我已经清楚地遵循了说明和代码。
【问题讨论】: