I'm writing an Excel VBA macro using Selenium and Chromedriver. The following code successfully opens Chrome to the desired webpage and then enters an address in the search text box. For the detailed information for that address to appear you need to press the "Enter" key (try it manually). You can see in the code below the various code approaches I've tried to press "Enter" but with no success. How can I press the "Enter" key programmatically and have the address information appear on the webpage?
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
CodePudding user response:
I suggest that you use Option Explicit at the top of your modules. I declared two variables in your procedure because they are not visible on your code. I tried and it works.
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