WebBrowser Dialogs

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
4 posts Page 1 of 1
Contributors
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

WebBrowser Dialogs
M1z23R
How would i block ALL, but i mean all dialogs from webbrowser ?Not just scripterrors/downloads, but i mean all.
I need this because i am trying to make my own automated application (bot), but i hate when the page needs to refresh it self, it always shows the "Retry/Cancle" dialog, how would i disable it, and all other dialog that could stop my application ?
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: WebBrowser Dialogs
mandai
It should be possible to run a seperate thread to look for any window titles that are not wanted, then these can be responded to automatically.
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

Re: WebBrowser Dialogs
M1z23R
How would i do that ?
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: WebBrowser Dialogs
mandai
You could use this:
Code: Select all
Imports System.Windows.Automation
Code: Select all

    Delegate Function del_getHandle() As IntPtr
    Function getHandle() As IntPtr
        Return Me.Handle
    End Function


    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

        While True

            Dim handle As IntPtr = Me.Invoke(New del_getHandle(AddressOf getHandle))
            Dim ae As AutomationElement = AutomationElement.FromHandle(handle)

            ae = ae.FindFirst(TreeScope.Descendants, New PropertyCondition(AutomationElement.NameProperty, "Windows Internet Explorer"))
            'find the warning window
            If ae <> Nothing Then
                ae = ae.FindFirst(TreeScope.Descendants, New PropertyCondition(AutomationElement.NameProperty, "Retry"))
                If ae <> Nothing Then
                    Dim ip As InvokePattern = ae.GetCurrentPattern(InvokePattern.Pattern)
                    ip.Invoke() 'click the retry button
                End If
            Else
            End If

            Threading.Thread.Sleep(100)
        End While

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        BackgroundWorker1.RunWorkerAsync()
    End Sub
You will also need to add the UIAutomationClient and UIAutomationTypes references.
4 posts Page 1 of 1
Return to “Tutorial Requests”