Microsoft Edge: Get Window URL and Title

后端 未结 7 1088
滥情空心
滥情空心 2020-12-06 15:33

Previously I was using ShellWindows() API for IE to get the window Title and URL for my application Now with new development, Microsoft Edge is new and has many features und

相关标签:
7条回答
  • 2020-12-06 16:13

    Dim tmp1 As String = "" Dim strME As String = "Microsoft Edge"

        Try
            Dim conditions As Condition = Condition.TrueCondition
            Dim BaseElement As AutomationElement = AutomationElement.RootElement
            Dim elementCollection As AutomationElementCollection = BaseElement.FindAll(TreeScope.Children, conditions)
            Dim AE As AutomationElement
    
            For Each AE In elementCollection
                If AE IsNot Nothing Then
                    tmp1 = AE.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString
                    If StrComp(Strings.Right(tmp1, strME.Length), strME, vbTextCompare) = 0 Then
                        Dim elmUrlBar0 As AutomationElement
                        elmUrlBar0 = AE.FindFirst(TreeScope.Subtree, New PropertyCondition(AutomationElement.AutomationIdProperty, "addressEditBox"))
                        If elmUrlBar0 IsNot Nothing Then
                            Dim patterns0 As AutomationPattern() = elmUrlBar0.GetSupportedPatterns()
                            If patterns0.Length > 0 Then
                                Dim val As ValuePattern = DirectCast(elmUrlBar0.GetCurrentPattern(patterns0(0)), ValuePattern)
                                If Not elmUrlBar0.GetCurrentPropertyValue(AutomationElement.HasKeyboardFocusProperty) Then
                                    Dim pvgc As String = LCase(val.Current.Value).Trim
                                    If pvgc.ToString <> "" Then
                                        urls = pvgc.ToString
                                        MsgBox(urls)
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            Next
    
        Catch ex As Exception
            MsgBox("Function AutomationElementData system error." + vbCr + vbCr + ex.ToString, vbExclamation)
        End Try
    
    0 讨论(0)
提交回复
热议问题