按 "Enter" 使用 Excel VBA-Selenium
Press "Enter" using Excel VBA-Selenium
我正在使用 Selenium 和 Chrome 驱动程序编写 Excel VBA 宏。以下代码成功打开 Chrome 到所需的网页,然后在搜索文本框中输入地址。要显示该地址的详细信息,您需要按“Enter”键(手动尝试)。您可以在下面的代码中看到我尝试按“Enter”但没有成功的各种代码方法。如何以编程方式按下“Enter”键并在网页上显示地址信息?
Dim WDriver As New WebDriver
Sub Q_Streets_TxtBox()
' Open Chrome and navigate to assessor's E-Mapping webpage
WDriver.Start "chrome", ""
WDriver.Get "https://maps.boco.solutions/propertysearch/"
WDriver.Window.Maximize
Application.Wait (Now + TimeValue("0:00:07"))
acct_addr = "1327 AGAPE WAY"
' Focus, clear the text box and enter the acct address
WDriver.FindElementById("searchField").SendKeys ("") ' focus
WDriver.FindElementById("searchField").Clear
WDriver.FindElementById("searchField").SendKeys acct_addr
' Press the "Enter" key - the following attempts failed
' WDriver.FindElementById("searchField").SendKeys Keys.Enter
' WDriver.FindElementById("searchField").submit
' WDriver.FindElementById("searchField").SendKeys (Keys.Enter)
' WDriver.FindElementById("searchField").Click
' do stuff
End Sub
我建议您在模块顶部使用 Option Explicit。
我在您的过程中声明了两个变量,因为它们在您的代码中不可见。我试过了,效果很好。
Sub Q_Streets_TxtBox()
Dim acct_addr As String
Dim keys As New Selenium.keys
'....
' Press the "Enter" key
WDriver.FindElementById("searchField").SendKeys (keys.Enter)
' do stuff
End Sub
我正在使用 Selenium 和 Chrome 驱动程序编写 Excel VBA 宏。以下代码成功打开 Chrome 到所需的网页,然后在搜索文本框中输入地址。要显示该地址的详细信息,您需要按“Enter”键(手动尝试)。您可以在下面的代码中看到我尝试按“Enter”但没有成功的各种代码方法。如何以编程方式按下“Enter”键并在网页上显示地址信息?
Dim WDriver As New WebDriver
Sub Q_Streets_TxtBox()
' Open Chrome and navigate to assessor's E-Mapping webpage
WDriver.Start "chrome", ""
WDriver.Get "https://maps.boco.solutions/propertysearch/"
WDriver.Window.Maximize
Application.Wait (Now + TimeValue("0:00:07"))
acct_addr = "1327 AGAPE WAY"
' Focus, clear the text box and enter the acct address
WDriver.FindElementById("searchField").SendKeys ("") ' focus
WDriver.FindElementById("searchField").Clear
WDriver.FindElementById("searchField").SendKeys acct_addr
' Press the "Enter" key - the following attempts failed
' WDriver.FindElementById("searchField").SendKeys Keys.Enter
' WDriver.FindElementById("searchField").submit
' WDriver.FindElementById("searchField").SendKeys (Keys.Enter)
' WDriver.FindElementById("searchField").Click
' do stuff
End Sub
我建议您在模块顶部使用 Option Explicit。 我在您的过程中声明了两个变量,因为它们在您的代码中不可见。我试过了,效果很好。
Sub Q_Streets_TxtBox()
Dim acct_addr As String
Dim keys As New Selenium.keys
'....
' Press the "Enter" key
WDriver.FindElementById("searchField").SendKeys (keys.Enter)
' do stuff
End Sub