【问题标题】:Clicking a Java script button using excel使用 excel 单击 Javascript 按钮
【发布时间】:2014-03-03 01:52:05
【问题描述】:

我正在尝试使用 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

【问题讨论】:

    标签: java javascript excel button click


    【解决方案1】:

    这对我有用

    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
    

    【讨论】:

    • 非常感谢!!起初这对我不起作用,但我在搜索功能之前添加了 Application.Wait (Now() + TimeValue("00:00:02")) 并且它起作用了。非常感谢!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-11
    • 1970-01-01
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多