Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15990

Get a Chrome URL

$
0
0
I'm trying to get a Chrome URL but I get an error:

System.MissingMethodException: 'Method not found: 'System.Windows.Rect System.Windows.Automation.Provider.IRawElementProviderFragment.get_BoundingRectangle()'.'

when I use this code:
Code:

Dim procsChrome As Process() = Process.GetProcessesByName("chrome")
    For Each chrome As Process In procsChrome
        If chrome.MainWindowHandle = IntPtr.Zero Then Continue For
        Dim elm As AutomationElement = AutomationElement.FromHandle(chrome.MainWindowHandle)
        Dim elmUrlBar As AutomationElement = elm.FindFirst(TreeScope.Descendants, New PropertyCondition(AutomationElement.NameProperty, "Address and search bar"))
        If elmUrlBar IsNot Nothing Then
            Dim patterns As AutomationPattern() = elmUrlBar.GetSupportedPatterns()
            If patterns.Length > 0 Then
                Dim val As ValuePattern = DirectCast(elmUrlBar.GetCurrentPattern(patterns(0)), ValuePattern)
                If Not elmUrlBar.GetCurrentPropertyValue(AutomationElement.HasKeyboardFocusProperty) Then Debug.Print(LCase(val.Current.Value).Trim)
                Exit For
            End If
        End If
    Next

The error appears in this line:
Code:

Dim elm As AutomationElement = AutomationElement.FromHandle(chrome.MainWindowHandle)

Viewing all articles
Browse latest Browse all 15990

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>