在短 VBA 代码上使用 Chrome Selenium 的 Web Scrape 单击按钮

Web Scrape click button with Chrome Selenium on short VBA code

提问人:tony2000 提问时间:6/27/2023 最后编辑:tony2000 更新时间:6/27/2023 访问量:54

问:

我的目标是点击下面URL的提交按钮(在韩国)。 “https://datacentersupport.lenovo.com/us/ko/warrantylookup#/”。 VBA 源代码使用 Sendkeys 成功放置了“j30a7xlg”。

之后,要单击按钮,我尝试使用css选择器但没有成功。随附错误图像。

我也尝试了下面的xPath。但失败了。 冠心病。FindElementByXPath(“//*[@id='app-standalone-warrantylookup']/div/div[2]/div/div/div[2]/button and text()='제출']”)。点击

因此,请告知或编码如何单击按钮。 如果需要更多信息,请告诉我。


'VBA Code
Private BR_wty As New Selenium.ChromeDriver
Sub ChromeExe(ByVal c As ChromeDriver, ByVal URL As String)
c.Get URL
End Sub

Sub Scrape_WTYMY1() 'warranty   
Dim URL As String, i As Integer
URL = "https://datacentersupport.lenovo.com/us/ko/warrantylookup#/"
Call ChromeExe(BR_wty, URL)
    
Dim chd As New Selenium.ChromeDriver    '//Local var
Set chd = BR_wty
    
Application.ScreenUpdating = False
chd.FindElementByClass("button-placeholder__input").SendKeys "j30a7xlg"
    
'Q1: how to click button ERROR (image for Run-time error 11)
chd.FindElementByCss("#app-standalone-warrantylookup > div > div.warranty-lookup__content > div > div > div.basic-search__content > button").Click

Application.Wait Now() + TimeSerial(0, 0, 10)
    
Application.ScreenUpdating = True

     
End Sub

enter image description here任何VBA代码(草稿)或建议都将对我的目标有所帮助。

html vba selenium-webdriver 抓取网页

评论

0赞 Pᴇʜ 6/27/2023
我们需要您提供更好的信息:“错误”不是错误描述。我们需要 a) 你的意图是什么,你的目标是什么?b) 出了什么问题,它做了什么?c) 如果有错误,它在哪里,错误消息是什么?d) “如何获取下一个操作的新 URL” 如果您不告诉我们,我们怎么知道您的下一个操作是什么?请编辑您的问题并添加更多详细信息。
0赞 igittr 6/28/2023
首先使用 Find 方法捕获元素,然后在单击之前对元素尝试该方法。set myButton = chd.find....myButton.scrollIntoView
0赞 tony2000 6/29/2023
未解决。我尝试了 igittr 方法。但是我在“myButton = chd.FindElementByCss”。将 myButton 调暗为 Selenium.WebElement '运行时错误 '91': '对象变量或未设置块变量 myButton = chd。FindElementByCss(“#app-standalone-warrantylookup > div > div.warranty-lookup__content > div > div > div.basic-search__content > button”)

答: 暂无答案