I managed to solve this problem as follows:
The moment I need to take the browser to the home page,
Webbrowser1.Navigate(homepage), i did the following... When trying to go to the homepage and the browser is locked with active alert, I apply the method .Dispose() on the object, and yet I define it as = Nothing.
After that I create again a Webbrowser as the same characteristics, but it will have a different nine so I used a Random() to generate an object with a random name.
Since my application only has one Webbrowser, all the places where I make some request for my Webbrowser I need to use a code that searches the object by Ctype(), since I do not know the name of the new Webbrowsers that will be created.
So the code goes like this:
//Tenta redirecionar para página inicial
Try
//Procura o WebBrowser ativo
For Each ctrlsweb In Me.Controls
If (ctrlsweb.GetType() Is GetType(WebBrowser)) Then
Dim browserc As WebBrowser = CType(ctrlsweb, WebBrowser)
//Aqui você executa as ações para esse webbrowser que o codigo transformou em variável
browserc.Navigate(pagInicial)
End If
Next
//Se houver algum erro, então e
Catch ex As Exception
//Elimina o objeto Browser ativo
For Each ctrlsweb In Me.Controls
If (ctrlsweb.GetType() Is GetType(WebBrowser)) Then
Dim browserc As WebBrowser = CType(ctrlsweb, WebBrowser)
browserc.Focus()
SendKeys.Send("{ENTER}")
browserc.Dispose()
browserc = Nothing
End If
Next
//Gera um número randomico para usar no nome do objeto Browser
Dim geraRand As Random = New Random()
Dim numero As String = geraRand.Next(1013, 8939)
//Cria novo WebBrowser
Dim web As New WebBrowser
web.Name = "WebBrowser" & numero
web.Dock = DockStyle.Fill
web.ScriptErrorsSuppressed = True
End Try
If your Webbrowser has Handler actions as well as mine, for example Documentcompleted, Navigating, etc... you can use after the creation of Webbrowser this code:
AddHandler web.Navigating, Sub()
BarStatus.Text = "Carregando..."
StatusOK.Visible = True
//Mais código aqui...
End Sub
Possible duplicate of How to click the java script Alert ok via Webbrowser?
– Rovann Linhalis
https://answall.com/a/246480/69359
– Rovann Linhalis
in the above links, have the two forms, block the Alert to appear and click ok of windows.
– Rovann Linhalis
I had already tried to use a similar solution but without success! This solution is in C#, I don’t know much I’m trying to write this in VB, but I’m facing difficulties.
– Gabriel
I had already tried to inject in the head, something like "window.Alert = Function () { }", but also unsuccessfully.
– Gabriel