0

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
1
  • What are you trying to get? The autocomplete list? e.g. typing 1327 AGAPE WAY in the search field and 1327 AGAPE WAY LAFAYETTE appears in the list, is that what you want? Commented Oct 27, 2021 at 7:43

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.