填写数据并打开URL后点击Chrome浏览器上的按钮

问题描述 投票:0回答:1

我想使用 Excel VBA 通过 Chrome 打开 URL 来填写数据并点击提交按钮。

我写了打开URL的命令。

如何输入数据并提交表格?

我的代码:

Sub OpenHyperlinkInChrome()
    Dim chromeFileLocation As String
    Dim hyperlink As String
    hyperlink = "<URL OVER HERE>"
    chromeFileLocation = """C:\Program Files\Google\Chrome\Application\chrome.exe"""
    Shell (chromeFileLocation & "-url " & hyperlink)
  
    driver.FindElementByName("trackingId").Value = "123"
    driver.FindElementByID("epm-submit-button-announce").Click
End Sub

我在

driver.FindElementByName
上遇到语法错误。

我的字段 HTML 代码:

<input type="text" placeholder="Example: BLUE_SHOES_08. This information is for your tracking purposes." name="trackingId" class="a-input-text a-span12">

按钮 HTML 代码如下

<span id="epm-submit-button-announce" class="a-button-text a-text-center" aria-hidden="true">
        Submit
</span>

如何填写表格并提交?

excel vba google-chrome
1个回答
0
投票

问题在于您调用“驱动程序”对象时没有定义它,甚至没有声明它。 从代码来看,您正在尝试使用 Selenium,您安装了 Selenium 吗? 安装 Selenium 后,您的代码应如下所示:

Set driver = CreateObject("Selenium.ChromeDriver")
driver.start "chrome"
driver.Get "<URL OVER HERE>"
driver.FindElementByName("trackingId").SendKeys ("123")
driver.FindElementByID("epm-submit-button-announce").Click
© www.soinside.com 2019 - 2024. All rights reserved.