Manipulate text in a loaded html-page of the Webbrowser control in the DocumentCompleted event (vb.net) - vb.net

I already tried some solutions provided here, but I cannot get it to work. On my winform I have a webbrowser control which should load a webpage (aspx). In case the webpage isn't found, I want to let the user know that this page isn't found. To get this to work I use the following code:
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If (WebBrowser1.Document.Url.ToString().StartsWith("res:")) Then
Dim curDir As String = Directory.GetCurrentDirectory()
Dim Url As Uri = New Uri(String.Format("file:///{0}/Html/PageNotFound.html", curDir))
WebBrowser1.Navigate(Url)
End If
End Sub
This is working fine. The page PageNotFound.html is shown. However, I would like to provide the user with some additional information which I want to insert into the PageNotFound.html at realtime (i.e. using document.getElementById to manipulate a Label-tag). I just don't know how I can do this, or if it is even possible. Maybe I use the wrong event. something I also tried is:
With WebBrowser1
.Navigate("about:blank")
.Document.OpenNew(False)
.Document.Write(HtmlString)
.Refresh()
End With
Where the HtmlString contains a complete webform.(like: "")
Maybe someone put me the right direction? TIA

Related

Filling in email and password using a button on Microsoft login \w out API

I have been struggling to figure out on how to fill in the email and password on the page and click a button to log into Microsoft, but I cant figure it out. I am very new to VB.net and would like some help to get better at and to learn. so far I have:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("https://login.live.com/")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim elements = WebBrowser1.Document.GetElementsByTagName("input")
For Each element As HtmlElement In elements
If element.GetAttribute("type") = "submit" Then
element.InvokeMember("click")
Exit For
End If
Next
End Sub
I have tried to use the GetElementById("").SetAttribute("value", TextBox1.Text), but I'm having a hard time finding it. Could some one please point me in the right direction or show me some code on how to do this. Thanks so much!!!
If you want to type your username and password automatically, then you may have to take a look on AutoIt. It is a scripting anguage. You can easily do this with built-in functions. There is a COM version for AutoIt. So you can add reference to your vb.net project and import it to your class. And you can easily call almost all useful function from there. Give try. Here is the link
https://www.autoitscript.com/site/

VB.NET 2008 - Input to data to website controls and download results

this is my first Q on this website so let me know if I have missed any important details, and thanks in advance.
I have been asked to access a website and download the results from a user-inputted form. The website asks for a username/password and once accepted, several questions which are used to generate several answers.
Since I am unfamiliar with this area I have set up a simple windows form to tinker around with websites and try to pick things up. I have used a webbrowser control and a button to use it to view the website in question.
When I try to view the website through the control, I just get script errors and nothing loads up. I am guessing I am missing certain plug-ins on my form that IE can handle without errors. Is there anyway I can identify what these are and figure out what to do next? I am stumped.
The script errors are:
"Expected identifier, string or number" and
"The value of the property 'setsection' is null or undefined"
Both ask if I want to continue running scripts on the page. But it works in IE and I cannot see why my control is so different. It actually request a username and password which works fine, it is the next step that errors.
I can provide screenies or an extract from the website source html if needed.
Thanks,
Fwiw my code is:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'WebBrowser1.ScriptErrorsSuppressed = True
WebBrowser1.Navigate("http://website.com")
'WebBrowser1.Navigate("http://www.google.com")
End Sub
Thanks for Noseratio I have managed to get somewhere with this.
Even though the errors I was getting seemed to be related to some XML/Java/Whatever functionality going askew it was actually because my webbrowser control was using ie 7.0
I forced it into using ie 9 and all is now well. So, using my above example I basically did something like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'WebBrowser1.ScriptErrorsSuppressed = True
BrowserUpdate()
WebBrowser1.Navigate("http://website.com")
'WebBrowser1.Navigate("http://www.google.com")
End Sub
Sub BrowserUpdate()
Try
Dim IEVAlue As String = 9000 ' can be: 9999 , 9000, 8888, 8000, 7000
Dim targetApplication As String = Process.GetCurrentProcess.ToString & ".exe"
Dim localMachine As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
Dim parentKeyLocation As String = "SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl"
Dim keyName As String = "FEATURE_BROWSER_EMULATION"
Dim subKey As Microsoft.Win32.RegistryKey = localMachine.CreateSubKey(parentKeyLocation & "\" & keyName)
subKey.SetValue(targetApplication, IEVAlue, Microsoft.Win32.RegistryValueKind.DWord)
Catch ex As Exception
'Blah blah here
End Try
End Sub

Request.QueryString returns '<%=Request.QueryString('ID')%>' issue vb.net

I have an issue the Request.QueryString. When users clicks a button, the page supposed to redirect to another url with some value on it.
The current page has this url
http://localhost:61430/CM/cm08.aspx?ID=ABC123&PID=Y6543&APPTYPE=1
This is the button clicked method. I even try to store the Request.QueryString value inside a variable, and I still get '<%=Request.QueryString('ID')%>' in the 'test' variable content.
Protected Sub btnBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBack.Click, btnNo.Click
Dim test As String = Request.QueryString("ID")
Response.Redirect("cm02.aspx?ID=" & Request.QueryString("ID"))
End Sub
Anyhow, when the page loads the cm02 page, the url looks like this
http://localhost:61430/CM/cm02.aspx?ID=<%=Request.QueryString('ID')%>
How can I rectify this?
I'm pretty sure the problem is not there.
Search for this string (with single quote) in your code: QueryString('ID')

How to get HTML from the URL and display it in certain place?

I'm in progress with my first application in visual basic, and I'm using the visual basic studio - My question is, how can I get raw HTML data from specified URL, and then display it in my form on the certain position?
I havent tried anything yet, because I havent found much solutions about this on the internet.
You need to use the HttpClient class or the WebClient class to get the raw HTML as a string. Then, you can simply display the string in any control on your form such as a TextBox or Label control.
For instance:
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim client As WebClient = New WebClient()
Label1.Text = client.DownloadString("http://www.stackoverflow.com")
End Sub

Capture New Window in WebBrowser Control VB.NET

I've been searching a bit and I haven't been able to exactly find what I need. I need to contain a popup window within the WebBrowser control in VB.NET
I found this project: http://www.codeproject.com/KB/cpp/ExtendedWebBrowser.aspx
But I've been having trouble parsing out what I need from it. It looks like it implements what I need, but I'm not really sure how the heck it's doing it. I just need to capture a popup and display it in a new WebBrowser object.
Private Sub WebBrowser1_NewWindow(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
Dim myelement As HtmlElement = WebBrowser1.Document.ActiveElement
Dim target As String = myelement.GetAttribute("href")
Dim newinstance As New WebBrowser
newinstance.Show()
newinstance.Navigate(target)
e.Cancel = True
End Sub