无法让网页接受从 excel-vba 导入的数据

cant make a web page accept imported data from excel-vba

任何有关以下内容的帮助都会很棒...我正在使用 excel vba 将序列号上传到网页中,然后单击 'Check Warranty' 按钮在应该显示更多数据的页面中,但是当单击时,搜索字段中的输入数据消失并显示 'no product found..' 错误。 (如果我手动 type/paste 并单击按钮,效果很好)

Sub test()

Dim IE As New InternetExplorer
Dim Doc As HTMLDocument

IE.Visible = True

IE.navigate "https://pcsupport.lenovo.com/za/en/warrantylookup"

Do
 DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE

Set Doc = IE.document

Doc.getElementsByName("input_sn").Item("input_sn").Value = "PC0X5YHZ"

Doc.querySelector(".btn.btn-primary").Click

'should now take you to warranty detail page
'but just get error on web page "Sorry, no products were found that match that query......"


End Sub

HTML Code

以下作品使用 selenium basic。安装 selenium 后记得去 VBE > Tools > References > Add reference to Selenium Type Library

Option Explicit
Public Sub EnterInfo()
    Dim d As WebDriver
    Set d = New ChromeDriver
    Const URL = "https://pcsupport.lenovo.com/gb/en/warrantylookup"

    With d
        .Start "Chrome"
        .get URL
         .FindElementById("input_sn").SendKeys "pc0x5yhz"
         .FindElementByCss(".btn.btn-primary").Click

         Stop '<==Delete me later
        .Quit
    End With
End Sub

作弊你可以使用重定向 URL:

https://pcsupport.lenovo.com/gb/en/products/laptops-and-netbooks/thinkpad-x-series-laptops/thinkpad-x280-type-20kf-20ke/20ke/20kes5sd09/pc0x5yhz/warranty

作为 B 计划,您可以抓取机器类型信息以生成那些 URL,然后循环添加保修信息的那些 URL。

Doc.getElementsByName("input_sn").Item("input_sn").Value = "PC0X5YHZ" 
Doc.getElementById("input_sn").Focus
SendKeys "z+{BS}", True
Doc.querySelector(".btn.btn-primary").Click