2011-09-09 2 views
1

데스크탑 VB 응용 프로그램이 을 이미 제어 할 수있는 방법이 있습니까? 브라우저 창을여십시오. 예를 들어 마우스로 특정 좌표를 마우스로 클릭하거나 창에 특정 요소가 있는지 확인하십시오.vb 형식으로 이미 열려있는 브라우저를 제어/액세스하십시오.

Microsoft 인터넷 컨트롤 (shdocvw)과 MSHTML (IHTMLDocument2)을 사용하여 보았지만 브라우저 창의 요소 (예 : body.innnerHTML)에 액세스하는 방법에 어려움을 겪고 있습니다.

답변

0

는 마이크로 소프트 HTML 개체 라이브러리에 참조 추가 및 Microsoft Internet 특정 HTML 요소가있는 경우 나, 예를 들어, 브라우저 윈도우의 상태를 결정해야

Option Explicit On 

Public Class Form1 

    'Functions used to set cursor location and mouse clicks 
    Public Declare Auto Function SetCursorPos Lib "User32.dll" (ByVal X As Integer, ByVal Y As Integer) As Long 
    Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) 
    Public Declare Auto Function ShowWindow Lib "user32" (ByVal _ 
    hwnd As Long, ByVal nCmdShow As Long) As Long 

    'Constants used for cursor and mouse functions, and to maximize window 
    Public Const SW_MAXIMIZE = 3 
    Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down 
    Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up 
    Public Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down 
    Public Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up  

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
     'retrieve all the open instances of IE 
     Dim shellWindows = New SHDocVw.ShellWindowsClass() 
     Dim htmlInput As mshtml.HTMLInputElement 
     'for each instance of IE 
     For Each ie As SHDocVw.InternetExplorer In shellWindows 
     'If the title of the IE window matches the designated title 
     If ie.Document.title = "Page Title" Then 
      'retrieve the control with the designated field id 
      htmlInput = ie.Document.getElementById("fieldID") 
      'if the control's inner html matches the designated text 
      If htmlInput.innerHTML = "innerHTML" Then 
       'show the IE window maximized and with focus 
       ShowWindow(ie.HWND, SW_MAXIMIZE) 
       'move the cursor to the designated x,y coordinates 
       SetCursorPos(xCoord, yCoord) 
       'left mouse click down and up 
       mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) 
       mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) 
       'send the designated keyboard command 
       My.Computer.Keyboard.SendKeys("keyboardCommand") 
      End If 
     End If 
     Next 
    End Sub 
End Class 
1

당신은 당신이 TAB에 VB.NET

 set WshShell = WScript.CreateObject("WScript.Shell") 
    WshShell.Run "iexplore" 
    WScript.Sleep 100 
    WshShell.AppActivate "Windows Internet Explorer" 
    WshShell.SendKeys "~" 
    WScript.Sleep 500 
    WshShell.SendKeys "www.google.com" 

~입니다 사용할 수있다 VBScript로에서는 AppActivate를 사용할 수 있습니다, 당신은 키 입력을 에뮬레이트 SendKeys 매크로를 사용할 수 있습니다.

+0

제어합니다. – mp42871

+0

어쩌면 send keys 명령을 사용하여 소스를보고 더 많은 send keys 명령을 사용하여 해당 HTML을 클립 보드에 복사 할 수 있습니다. 그런 다음 앱에서 HTML을 클립 보드에서 가져 와서 액세스 할 수 있습니다. – N0Alias

+0

차라리 덜 고풍스러운 방식으로 코드에 액세스하고 싶습니다. – mp42871

관련 문제