我正在使用 Selenium 和 Chromedriver 撰寫 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
uj5u.com熱心網友回復:
我建議您在模塊頂部使用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
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/338671.html
下一篇:通過隱藏行的動態數字串列
