我正在尝试使用 VBA 单击以下网站上的 Java 脚本按钮:http://www.ura.gov.sg/realEstateIIWeb/transaction/search.action
我正在尝试让 vba 选择一个项目,然后单击标有“添加”的按钮,然后单击上面 Web 链接中标有“搜索”的按钮。
我已经设法让 VBA 打开网站并选择项目,但我无法让 VBA 单击“添加”按钮和“搜索”按钮
Sub DLDATA()
Dim MAS As Object
Dim STYR As Object
Dim DLD As Object
Dim XLD As Object
Dim form As Variant, button As Variant
Set MAS = CreateObject("InternetExplorer.application")
使用 MAS
.Visible = True
.Navigate Sheets("Property Value").Range("B30").Value ' Navigate to website
Do Until .ReadyState = 4
DoEvents
Loop
Set STYR = MAS.Document.all.Item("projectNameList")
STYR.Value = Sheets("Property Value").Range("A1").Value ' Select name of property based on name in cell A1.
Set XLD = MAS.Document.all.Item("addOpt")
XLD.Value = Sheets("Property Value").Range("A1").Value
End With
End Sub
最佳答案
这对我有用
Sub test()
URL = "http://www.ura.gov.sg/realEstateIIWeb/transaction/search.action"
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate URL
Do Until (ie.readyState = 4 And Not ie.Busy)
DoEvents
Loop
Set STYR = ie.Document.all.Item("projectNameList")
STYR.Value = Sheets("Property Value").Range("A1").Value ' Select name of property based on name in cell A1.
Set Results = ie.Document.getElementsByTagName("input") ' find and click the "add" button
For Each itm In Results
If InStr(1, itm.outerhtml, "addOpt", vbTextCompare) > 0 Then
itm.Click
Exit For
End If
Next
ie.Document.getElementByID("searchForm_0").Click ' click the "search" button
Do Until (ie.readyState = 4 And Not ie.Busy)
DoEvents
Loop
' do whatever
End Sub
关于java - 使用 excel 单击 Javascript 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21597474/