打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
关于vb.net:使用VB .Net和UI自动化从Google Chrome浏览器中所有打开的标签页获取网址 | 码农家园
userphoto

2023.04.26 北京

关注

您好,我正在使用此提取代码来获取Chrome上的当前网址,但只能获取有效的标签页面。我需要使用UI自动化从所有打开的选项卡。

我的工作代号:

1
2
3
4
5
6
7
8
9
10
11
12
13
函数GetChromeUrl ( ByVal proc As Process ) As String
    If proc 窗口句柄 = IntPtr 如果Dim element As System为零
    返回 Nothing
End 视窗自动化)如果元素_ _ _ _ _ _什么都不



    Return Nothing
End If

Dim edit As System 视窗自动化自动化元素 =元素_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
当前价值ToString
结束

并在Form Load事件中使用以下代码调用它:

1
2
3
针对 每个proc As Process In Process。GetProcessesByName chrome MsgBox proc.MainWindowTitle + + GetChromeUrl proc 下一步_
   
相关讨论
  • 不适合我...

你最好这样

1
2
3
4
5
6
7
8
9
10
11
12
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
39 40 41 42 43 44 4 4_47 _ _ _ _ 51





































进口无损检测客户端'为 firefox 导入系统导入 NDde 库运行时InteropServices 'For Chrome Private Const WM_GETTEXTLENGTH As Integer = & He Private Const WM_GETTEXT As Integer = & Hd < DllImport ( "user32.dll" ) > _ Private Shared Function SendMessage ( hWnd As IntPtr, Msg As UInteger







, wParam As Integer , lParam As Integer ) As Integer
End Function
< DllImport ( "user32.dll" ) > _
Private Shared Function SendMessage ( hWnd As IntPtr, Msg As UInteger , wParam As Integer , lParam As StringBuilder ) As Integer
End Function
< DllImport ( "user32.dll" , SetLastError : = True) > _
私有 共享 函数FindWindowEx ( parentHandle As IntPtr, childAfter As IntPtr, className As String , windowTitle As String ) As IntPtr
End Function

公共 共享 函数getChromeUrl ( winHandle As IntPtr ) As String
    Dim browserUrl As String = Nothing
    Dim urlHandle As IntPtr =FindWindowEx ( winHandle, IntPtr . Zero , "Chrome_AutocompleteEditView" , Nothing )
    Const nChars As Integer = 256
    Dim Buff As New StringBuilder ( nChars )
    Dim length As Integer = SendMessage ( urlHandle, WM_GETTEXTLENGTH, 0 , 0 )
    如果长度> 0 Then
        SendMessage ( urlHandle、WM_GETTEXT、nChars、浅黄色)
        浏览器网址=浅黄色ToString ( )

        返回browserUrl
    否则
        返回browserUrl
    End If

End Function

Public shared Function GetChromeHandle ( ) As Intptr
 Dim ChromeHandle As IntPtr = Nothing
 Dim Allpro ( ) As Process = Process 获取进程
 对于 每个ProcessName = " chrome "   ChromeHandle =专业MainWindowHandle Exit For End if Next返回ChromeHandle End Function ' USAGE FOR CHROME Dim CHandle As IntPtr = GetChromeHandle ( ) If Not CHandle , Equals ( Intptr . Zero ) Dim url As String= getChrome 网址
 

 
 
     




 
 
  ( CHandle )如果
 结束

来源并阅读更多

编辑:

我找到了自己的方式,对我有用

1
2
3
4
5
6
7
8
9
10
11
12
13
Dim appAs String ="chrome"
Dim proc As System.Diagnostics.Process = GetBrowser(app)
...
Private Function GetBrowser(ByVal appName) As System.Diagnostics.Process
    Dim pList() As System.Diagnostics.Process =  
 System.Diagnostics.Process.GetProcessesByName(app)
    For Each proc As System.Diagnostics.Process In pList
        If proc.ProcessName = appThen
            Return proc
        End If
    Next
    Return Nothing
End Function

用法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
If proc IsNot Nothing Then
    Dim browserName as string ="Google Chrome"
    Dim className as String ="Edit"
    Dim s As String =
GetCurrentUrl(proc.MainWindowHandle, browserName, className, ComboBox1)
    If s <>"" Then
        Msgbox.show(s)
        ComboBox1.SelectedIndex = 0 'Window list
    Else

    End If
Else
    Label1.Text = browserName &" is not available"
end If

希望能帮助到你 :))))


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
请问VB中URLEncode怎写?
VB实用代码,收藏!!
VB.NET 2005编写定时关机程序
VB.NET自动操作其他程序(2)
vb.net 枚举电脑上的TCP,UDP连接
VB6中一个非常好用的读写Ini文件的模块
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服