使用VBA代码在亚马逊卖家主页上查找元素的问题

时间:2015-11-04 20:16:21

标签: vba excel-vba amazon-web-services excel

我最近在使用Excel VBA代码时遇到了一个新问题,以便将来自单元格(订单号)的值自动输入到Amazon的搜索框中并搜索订单。我似乎无法找到适当的对象来引用亚马逊卖家主页主页上的搜索按钮,以便点击并继续。我的代码是这样的:

Option Explicit
Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Sub MyAmazonSeller()
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
Dim oSignInLink As HTMLLinkElement
Dim oInputEmail As HTMLInputElement
Dim oInputPassword As HTMLInputElement
Dim oInputSigninButton As HTMLInputButtonElement
Dim oInputSearchOrder As HTMLInputElement
Dim oInputSearchButton As HTMLInputButtonElement


MyURL = "https://sellercentral.amazon.com/gp/homepage.html"

Set MyBrowser = New InternetExplorer

' Open the browser and navigate.
With MyBrowser
    .Silent = True
    .Navigate MyURL
    .Visible = True
    Do
        DoEvents
    Loop Until .ReadyState = READYSTATE_COMPLETE
End With


' Get the html document.
Set HTMLDoc = MyBrowser.Document

' See if you have the sign in link is because you are in the main
' page
Set oSignInLink = HTMLDoc.getElementById("signin-button-container")
If Not oSignInLink Is Nothing Then
    oSignInLink.Click
    Do
        DoEvents
    Loop Until MyBrowser.ReadyState = READYSTATE_COMPLETE
End If

' Get the email field and the next button
Set oInputEmail = HTMLDoc.getElementById("username")
Set oInputPassword = HTMLDoc.getElementById("password")

' Click the button and wait
oInputEmail.Value = "xxxxxxxxx@xxxxxx.net"


' Get the password field and the sign in button
Set oInputPassword = HTMLDoc.getElementById("password")
Set oInputSigninButton = HTMLDoc.getElementById("sign-in-button")


' Click the button and wait
oInputPassword.Value = "xxxxxxxx"
oInputSigninButton.Click
  Do
    DoEvents
Loop Until MyBrowser.ReadyState = READYSTATE_COMPLETE



Set oInputSearchOrder = HTMLDoc.getElementById("sc-search-field")
oInputSearchOrder.Value = "110-7706193-5695453"
Set oInputSearchButton = HTMLDoc.getElementByClassName("sc-search-button")
oInputSearchButton.Click
  Do
    DoEvents
Loop Until MyBrowser.ReadyState = READYSTATE_COMPLETE
Err_Clear:
If Err <> 0 Then
    Err.Clear
    Resume Next
End If

End Sub

Err_Clear之前的部分是我一直在尝试修改和使用的新代码片段。似乎搜索按钮没有正确的ID,因此更难以引用。每次代码到达倒数第二个片段时,我都会收到错误91.

0 个答案:

没有答案