How to get HtmlDocument & active HtmlElementd from default web browser - vb.net

Dim webBrowser1 As Object = New WebBrowser
webBrowser1 = Process.Start(MemSite(CurrCell), ProcessWindowStyle.Maximized)
Dim HtmlDoc As HtmlDocument = webBrowser1.Document
Dim htmlElem As HtmlElement = HtmlDoc.All.Item(0)
If htmlElem.TagName = "HTML" Then
End If
Trying to get Active elements from default web browser without using
form layout + Web Browser Control.
and post the username + password.

Short answer: What you are trying to achieve is not possible.
Long answer:
Each web browser has its own way of managing the HTML DOM. There isn't a universal solution that'll work for all of them.
The only way this can be done is if you get ahold of an API for each web browser you want to target, and then decide which API to use based on which the user has installed as his/her default. Doing so will require A LOT of time and effort, but it is technically possible (assuming the browsers you want to target have a public API that can be used for automation).

Related

Logging into a MFP web interface using vb.net

I am trying to use a VB windows form app to control multiple MFP's. I would like to be able to log in to the MFP's with a single button click as the username and passwords are all the same. I have been able to do this on other web interface pages but the web interface page on these Toshiba MFP's is different. It has a main page an then a folder with other page elements and JavaScript's. Any help or direction is appreciated.
` Dim UN As String = "admin"
Dim PW As String = "123456"
WebBrowser1.Document.Forms(0).All("login").SetAttribute("value", UN)
WebBrowser1.Document.Forms(0).All("passwd").SetAttribute("value", PW)
[]

Windows 8 Metro Show Webview in Popup and pass response back OAUTH2 Visual Basic

This is my first question so hello and thanks for your support!
I am currently developing a windows 8 store app.
I need to login to an OAUTH website and get the response token to save as a string.
I would like this to appear in a popup, have the user login, then close once a response is received.
I can get the webview to pop up and I can navigate to the page. But how do i handle the response and close. I speak VB.
Thanks again!
Edited to add my code:
Dim url As New Uri("https://aurlthatidontcontrol")
WebView1.Navigate(url)
PopUp.IsOpen = True
MY popup opens and the login for the url is presented.
Once I log in I should get a response from that server which includes an access token
I want to get that token into my app and save it as a string, then close the popup
Ok I figure it out.
Instead of actually calling a webview I used the web-broker authentication. Details
This allows the service login to "pop" on the screen and I can capture the result like this:
Dim webresult As WebAuthenticationResult = Await
WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, StartURI, endURI)
Dim finalresponse() As String = webresult.ResponseData.ToString.Split("=")
Dim currentuserstoken As String = finalresponse(1)
Return currentuserstoken
Use the InvokeScript method on the WebView class to call JavaScript code to collect information from the response and return it the calling code. If there is no script in the page you control, use "eval" as the function name and pass arguments to it.
Alternatively, use window.external.notify in JavaScript to fire the ScriptNotify event (link includes an example).

In VBA after automated xml form post, how can I automate interaction with the response?

I am using xml in VBA. The code below adds an item to a shopping cart on a remote website (posts a form). Then the code displays the result in Internet Explorer.
You can see in the response there is a "get estimates" button. I need to automatically click that, enter location info, and get the response of shipping and tax charges (for the item currently in the cart) on my excel 2010 worksheet.
I want all the automated clicking and entering data to happen with the site (the site's server?) directly like when I added the item to the shopping cart, not through the browser if possible. It takes a long time for the page to load and I think if I go through a browser I could do that without xml anyway. But I'm really stuck so if I have to load a browser that's okay too.
Option Explicit
Sub testing()
Dim objIE As Object
Dim xmlhttp As Object
Dim response As String
Set objIE = CreateObject("InternetExplorer.Application")
objIE.navigate "about:blank"
objIE.Visible = True
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
'~~> Indicates that page that will receive the request and the type of request being submitted
xmlhttp.Open "POST", "http://www.craft-e-corner.com/addtocart.aspx?returnurl=showproduct.aspx%3fProductID%3d2688%26SEName%3dnew-testament-cricut-cartridge", False
'~~> Indicate that the body of the request contains form data
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
'~~> Send the data as name/value pairs
xmlhttp.Send "Quantity=1&VariantID=2705&ProductID=2688"
response = xmlhttp.responseText
objIE.Document.Write response
Set xmlhttp = Nothing
End Sub
What you can do is:
Use XMLHTTP to retrieve the source of the page
Use the MSHTML object model to further automate the page
Example:
An exploration of IE browser methods, part II
What the code on this page does is:
Take advantage of XMLHTTP's speed to retrieve a webpage source faster than automating IE
Assign the XMLHTTP response to a MSHTML Document object (effectively 'loading' the page inside the DOM), then
Use traditional OM methods for looping through page objects, clicking buttons and so on.
At the risk of self-aggrandizement, Tim's advice is spot on. The link he provided has several methods you could use (after getting the page using XMLHTTP, of course) for either iterating through the page and clicking the "Get Estimates" button, or setting a reference to it directly and calling the HTMLInputElement.Click method.

Watin login without seeing the page

I want to do a automatic login on a web without seeing the page (it have to be transparent for the user). All have to by using c#.
I thought that maybe with watin i can do it. I can login into a web seeing it, but i wonder if i could do it without seeing it.
Any ideas?
Thanks
You can hide the IE window with:
Settings.Instance.MakeNewIeInstanceVisible = false;
ie = new IE(true);
OR
ie = new IE(true);
ie.ShowWindow(NativeMethods.WindowShowStyle.Hide);
.
You can minimize the IE window with:
ie = new IE(true);
ie.ShowWindow(NativeMethods.WindowShowStyle.Minimize);

onclick event activation

I am sending web requests to a site and getting the responsestream and would like to perform the button click programatically, here is the tag for the event:
Next ยป
any ideas appreciated?
I used a web browser control... it might not have been the best approach since I don't know what page it's on, but here's my code:
Dim wb As WebBrowser = New WebBrowser
wb.Navigate("http://www.mydomain.com")
wb.Document.GetElementsByTagName("a")(2).InvokeMember("click")
This basically "clicks" the 3rd (the array is 0-based) tag on the current page.
HTH