I need Help Making my VB 2008 Express Web Browser - vb.net

Every time I click on a link it opens in Internet Explorer but I want it to open in another window of my web browser.
Details:
I created a tabbed web browser which is using a tab control. Other Controls would be a normal web browser.

You have to hookup the newwindow2 of the (old activex) browser control event like this:
Private Sub AxWebBrowser1_NewWindow2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NewWindow2Event) Handles AxWebBrowser1.NewWindow2
Dim frmWB As Form1
frmWB = New Form1()
frmWB.AxWebBrowser1.RegisterAsBrowser = True
e.ppDisp = frmWB.AxWebBrowser1.Application
frmWB.Visible = True
End Sub
Details can be found here http://support.microsoft.com/?scid=kb%3Ben-us%3B311282&x=8&y=21

Related

How to close a browser tab when clicking on a Button? Visual Basic 2019

I need some help in the following situation, I am creating an Agenda in VB.net (visual basic 2019), in my Form I have a Button1 that when clicking it opens a certain web page in a tab in the chrome browser, however I need to do the opposite, that when clicking on a Button2 it closes only the tab opened by Button1 without closing the browser.
Public Class FrmAgenda
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim weblink As String
weblink = "www.google.com"
System.Diagnostics.Process.Start("chrome.exe", weblink)
End Sub
End Class

Selenium with chrome shows console window of chrome driver , get page complete events

I am using Selenium for chrome browser automation. I want to open a webpage and fill a login form , submit etc.
Below is a part of code
Dim chromeOptions As New OpenQA.Selenium.Chrome.ChromeOptions()
chromeOptions.AddExcludedArgument("ignore-certifcate-errors")
chromeOptions.AddArgument("test-type")
Dim driver As IWebDriver = New ChromeDriver(chromeOptions)
driver.Navigate().GoToUrl("https://example.com")
Dim myLink1 As IWebElement = driver.FindElement(By.Name("userName"))
myLink1.SendKeys("username")
Dim myLink2 As IWebElement = driver.FindElement(By.Name("password"))
myLink2.SendKeys("mypassword")
It works properly. But when i run the application a console window appears when chrome gets open. It is due to chromedriver.exe And cond=sole windows shows "Starting ChromeDriver (v2.9.248315) on port 2078". But I don't want this console window to appear as user suing application will not require it and understand what it is.So is there any way to avoid this console window?
Also how can I get page complete events once the page gets loaded completely?
EDIT
Like in Document complete which is available for web browser controls. After reading selenium documentation I found that there exists a EventFiringWebDriver which may do what I want(like OnNavigated ) And chromeDriver does not have these. But i didnt get any example of how it(EventFiringWebDriver ) can be used with Onnavigated functions etc to get these events.
EDIT
What I did is
Imports OpenQA.Selenium
Imports OpenQA.Selenium.Chrome
Imports OpenQA.Selenium.Support.Events
Dim service As ChromeDriverService = ChromeDriverService.CreateDefaultService
Dim driver1 As ChromeDriver = Nothing
Dim driver As EventFiringWebDriver
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim chromeOptions As New OpenQA.Selenium.Chrome.ChromeOptions()
chromeOptions.AddExcludedArgument("ignore-certifcate-errors")
chromeOptions.AddArgument("test-type")
service.HideCommandPromptWindow = True
driver1 = New ChromeDriver(service, chromeOptions)
driver = New EventFiringWebDriver(driver1)
AddHandler driver.Navigated, AddressOf OnNavigated
driver.Navigate().GoToUrl("https://example.com")
Dim myLink1 As IWebElement = driver.FindElement(By.Name("userName"))
myLink1.SendKeys("username")
Dim myLink2 As IWebElement = driver.FindElement(By.Name("password"))
myLink2.SendKeys("mypassword")
End Sub
Protected Sub OnNavigated(ByVal sender As Object, ByVal e As Support.Events.WebDriverNavigationEventArgs)
MessageBox.Show("Page navaigated " & e.Url)
End Sub
End Class
After page gets navigated OnNavigated function triggered as I expected. But after page gets navigated and user name and password filled and if user clicks on login button manually a new page will appear after login. During this new page gets navigated it wont trigger OnNavigated .But i want to get notification for every page that gets navigated even from user inputs. So how this can be achieved?
The default behavior of displaying the command prompt window is a feature, not a bug. Many people insist on using the .Close() method to exit the browser window instead of .Quit(). However, this would close the browser, but not clean up all resources, like exiting the chromedriver.exe instance. Thus, the .NET bindings maintainer made a conscious decision to make it absolutely clear when the executable is running and when it isn't. You can change this behavior by using code similar to the following:
Dim service As OpenQA.Selenium.Chrome.ChromeDriverService = OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService()
service.HideCommandPromptWindow = True
Dim chromeOptions As New OpenQA.Selenium.Chrome.ChromeOptions()
chromeOptions.AddExcludedArgument("ignore-certifcate-errors")
chromeOptions.AddArgument("test-type")
Dim driver As IWebDriver = New ChromeDriver(service, chromeOptions)
It's generally considered bad form to ask multiple unrelated questions in a single post on StackOverflow, but as for your second question, Are you asking, "How do I know when a page is completely loaded using WebDriver?" If so, then the answer is, "You don't." Or, more accurately, the question is meaningless when you're talking about today's JavaScript-heavy, AJAX-enabled, dynamically-generated-DOM world.
If you need to make sure an element is present on a page before you can interact with it, you can wait for that condition. The support library (in the WebDriver.Support.dll assembly in .NET) contains a WebDriverWait class designed to enable exactly that.
You could also try using the EventFiringWebDriver, which has a Navigated event. You would use standard VB.NET event handling code to hook this up (AddHandler/RemoveHandler). However, DO NOT conflate this .NET bindings event with the type of events you receive from Internet Explorer's COM object, like its DocumentComplete event. No such construct exists in the WebDriver API. The Navigated event is only raised when you manually navigate to a page (i.e., not on element clicks that cause navigation), and there is no guarantee whatsoever that any particular DOM event will have fired when the Navigated event is raised. The code to use it would look something like this:
' Assumes you have a sub with a declaration like this:
' Private Sub Navigated(sender As Object, e As WebDriverNavigationEventArgs)
Dim driver As IWebDriver = New ChromeDriver(service, chromeOptions)
Dim eventDriver As New EventFiringWebDriver(driver)
AddHandler eventDriver.Navigated, AddressOf Navigated
Once again, and I cannot stress this enough, if you're looking for an event that means "the page is loaded," You're Doing It Wrong™. The right thing to do is identify some element on the target page that will be present, and wait for that element to be available.

Visual Basic - Web browser load URLs from text

i am not so great with Visual basic, but i need some help on creating a web browser that would load several links import from a text file, and for the web browser to navigate to them. This is what i have so far
Dim link As String = OpenFileDialog2.FileName
Dim links As String = IO.File.ReadAllText(link)
MsgBox(links)
WebBrowser1.Navigate(links)
You help means a lot. Thank You.
The WebBrowser Control either will show the webpage in the Control which will limit you to one page, or you can tell it to open the pages in separate windows which will open an Internet Explorer window for each link. I also used the File.ReadAllLines Method in order to get an array of the Links so that you can iterate through the Web Pages . This works for me but might not be what you are wanting.
Public Class Form1
Dim wb As New WebBrowser
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim filename As String = "C:\temp\links.txt"
Dim links As String() = IO.File.ReadAllLines(filename)
For Each link As String In links
wb.Navigate(link, True)
Next
End Sub
Public Sub New()
InitializeComponent()
Controls.Add(wb)
wb.Dock = DockStyle.Fill
End Sub
End Class
My text file called Links.txt looks like this:
www.google.com
www.msdn.com
www.bing.com

VB.NET WebBrowser control - how do you submit to default browser?

I have a webbrowser control in my VBForm.
It looks for a website on my site and displays it.
There are form submit buttons in that WebBrowser1.
I would like it to be so that when they click a button in the WebBrowser1 Web page it will open their own browser to submit the form
How do i do this?
(yes, it's my website. i can change the HTML on the server if that is needed. )
answer is thanks to: Opening default web browser
and: vb.net WebBrowser links to Default Web Browser
and some trial and error. working result follows:
Private Sub WebBrowser1_Navigating(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
'added a match string - if Allow is inside the URL link, then the WebBrowser control is allowed to navigate to it. otherwise use their browser.
dim Allow as string = "http://mysite.com"
If InStr(e.Url.ToString(), Allow) = 0 Then
' I'm trying here to cancel the event so that the WebBrowser1 control doesn't go there.
e.Cancel = True
' then start a new process with their default browser
System.Diagnostics.Process.Start(getDefaultBrowser(), e.Url.ToString())
End If
End Sub
Private Function getDefaultBrowser() As String
Dim browser As String = String.Empty
Dim key As RegistryKey = Nothing
Try
key = Registry.ClassesRoot.OpenSubKey("HTTP\shell\open\command", False)
'trim off quotes
browser = key.GetValue(Nothing).ToString().ToLower().Replace("""", "")
If Not browser.EndsWith("exe") Then
'get rid of everything after the ".exe"
browser = browser.Substring(0, browser.LastIndexOf(".exe") + 4)
End If
Finally
If key IsNot Nothing Then
key.Close()
End If
End Try
Return browser
End Function
I never would of solved it if Martin Parkin didn't post up that duplicate warning.
also - had to change my links to METHOD = GET, the post headers don't always translate in this manner.

Add firewall exception

I'm working on a server/client TCP communication and it works fine, altough I can't make an application to add the software to the Windows firewall exception. I did found a sample, but it didn't worked.
My code:
Imports NetFwTypeLib
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim appType As Type = Type.GetTypeFromProgID("HnetCfg.FwAuthorizedApplication")
Dim app As INetFwAuthorizedApplication
app = DirectCast(Activator.CreateInstance(appType), INetFwAuthorizedApplication)
' Set the application properties
app.Name = "My App"
app.ProcessImageFileName = "c:\users\klein\documents\visual studio 2012\projects\tcp_server\tcp_server\bin\debug\tcp_server.exe"
app.Enabled = True
' Get the firewall manager, so we can get the list of authorized apps
Dim fwMgrType As Type = Type.GetTypeFromProgID("HnetCfg.FwMgr")
Dim fwMgr As INetFwMgr
fwMgr = DirectCast(Activator.CreateInstance(fwMgrType), INetFwMgr)
' Get the list of authorized applications from the Firewall Manager, so we can add our app to that list
Dim apps As INetFwAuthorizedApplications
apps = fwMgr.LocalPolicy.CurrentProfile.AuthorizedApplications
apps.Add(app)
End Sub
End Class
The code runs perfectly, no exception detected. Yet, the program is not listed after the form is loaded.
Thank you.
Look at this:
Programatically Add Exceptions to a Windows Firewall Using C#