首页 > 解决方案 > 单击没有按钮 ID、类名的搜索按钮

问题描述

我想单击搜索按钮以打开一个可以搜索的新页面。
我无法单击搜索按钮,因为检查元素代码中只给出了按钮名称。

button type="button" on click="window.location='Go?action=agent'" Search /button

我无法提供 URL,因为它在办公室外无法使用。

从下面的代码中,我可以登录页面,然后可以转到搜索按钮所在的页面。之后我被困在那个页面上。

Sub login_page()
    
    Dim IE App As Internet Explorer
    
    Dim IE Doc As Object
    
    'create a new instance of IE
    Set IE App = New Internet Explorer
    
    IE App.Visible = True
    
    IE App.navigate "URL"
    
    Do While IE App.Busy: Do Events: Loop
    
    Do Until IE App.ready State = READY STATE_COMPLETE: Do Events: Loop
    
    Set IE Doc = IE App.document
    
    With IE Doc.forms(0)
        .user.Value = "id"
        .Password.Value = "password"
        .submit
    End With

    IE App.navigate "hyperlink URL"
    
    Do While IE App.Busy: Do Events: Loop
    
    'Do Until IE App.ready State = READY STATE_COMPLETE: Do Events: Loop
    
    IE App.navigate "hyperlink URL"
    
    Do While IE App.Busy: Do Events: Loop
    
    IE App.navigate "hyperlink URL"
    
    Do While IE App.Busy: Do Events: Loop

    ieApp.document.getElementsById("go").Value = "123"
      
    With ieApp.document
        .getElementById("go").Value = "123"
    End With
    
    ieApp.document.parentWindow.getElementsbyid("go").Value = "123"
    
    ieApp.document.parentWindow.getElementbyid("go").Value = "123"
    
    ieApp.document.getElementById("go").Value = "123"

End Sub

标签: excelvbaweb-scraping

解决方案


在我直接运行 onclick 事件 javascript 的地方尝试类似以下的操作。

 ieApp.document.parentWindow.execScript "window.location='Go?action=agent'" 

推荐阅读