Interface With Browser Programmatically by Using LabVIEW

Updated Jan 5, 2021

There are two approaches available in LabVIEW for users to interact with the browser. One is by using .NET's WebBrowser and another is by using ActiveX's Microsoft Web Browser. In this article, both approaches will be discussed and demonstrated by using an example of how to search for "definition of happy" by using Yahoo Search.

.NET's Web Browser


Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.

Below is the explanation for each step mentioned in the VI snippet above:
  1. Get the control of .NET container with WebBrowser as its control and navigate it to the desired web page.
  2. Put a time delay for the WebBrowser to wait for its loading to complete.
  3. Get the HTML code of the web page.
  4. Get the ID of the search input and set your search term as its value.
  5. Get the ID of the search button and invoke its click method.
  6. The .NET web browser control in the front panel should display the search result at this step. The empty while loop with a button is used in this step is to retain the search result at the front panel. Stop the while loop will remove the search result and close the reference of .NET Web Browser control.
 

ActiveX's Microsoft Web Browser


Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.

Below is the explanation for each step mentioned in the VI snippet above:
  1. Get the control of the ActiveX container with Microsoft Web Browser as its control and navigate it to the desired web page.
  2. Wait for the web browser to complete its loading.
  3. Get the HTML code of the web page.
  4. Get the name or ID of the search input and set your search term as its value.
  5. Get the name or ID of the search button and invoke its click method.
  6. The ActiveX web browser control in the front panel should display the search result after Step 5. Unlike .NET web browser, an empty while loop with a button is not required because the search result at the front panel will still be retained after the VI stop running. This step is used to close the reference of ActiveX web browser control.