How to see if an object is blocked in Vb.net Webbrowser - vb.net

I have a webbrowser in a form that I am trying to see, if the following two items being displayed or not
<div class="alert alert-danger bet" style="display: block;">You Lost</div>
<div class="alert alert-success bet" style="display: none;">You Won</div>
I have searched and I can not find a solution to this. I have found how to search for them and find them without them having an ID but i can not see the style. If possible i would like to put the style result in a textbox for now until i figure out how to deal with the outcome.
EDIT
Ok so here's where i am now
Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("DIV")
For Each curElement As HtmlElement In theElementCollection
If curElement.OuterHtml.Contains("alert alert-danger bet") Then
TextBox1.Text = curElement.GetAttribute("style")
End If
Next
This returns System._ComObject and it seems to be the only thing that i can get to return at all.
Any suggestions?

OK so finally I believe I have a solution.
Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("DIV")
For Each curElement As HtmlElement In theElementCollection
If curElement.OuterHtml.Contains("alert alert-danger bet") Then
If curElement.Style = "display: block;" Then
TextBox1.Text = "True"
ElseIf curElement.Style = "display: none;" Then
TextBox1.Text = "False"
End If
End If
Next
End If
Next
Now obviously this is only showing one of my items so I will still have to handle the other but at least this gives me a True or False statement.

Related

Entering text in text box inside a webbrowser

I am connecting to a website trough a webbrowser, then i want to post a message on a message board.
This is the HTML of the text box:
<div class="fr-element fr-view" dir="ltr" contenteditable="true" style="min-height: 100px;" aria-disabled="false" spellcheck="true"><p>TEXT GOES HERE</p></div>
I have tried the following 2 codes:
For Each CurrentElement As HtmlElement In WebBrowser1.Document.GetElementsByTagName("div")
If CurrentElement.GetAttribute("class") = "fr-element fr-view" Then
CurrentElement.InnerText = TextBox1.Text
End If
Next
For Each CurrentElement As HtmlElement In WebBrowser1.Document.GetElementsByTagName("div")
If CurrentElement.GetAttribute("class") = "fr-element fr-view" Then
For Each InnerCurrentElement As HtmlElement In CurrentElement.GetElementsByTagName("p")
InnerCurrentElement.InnerText = RichTextBox1.Text
Next
End If
Next
None of them does anything
I really havent even messed around with HTML before this at all even so I am not sure what I could search for to solve my issue as I am able to handle other text boxes, for example the login ones which are like this:
<input type="text" class="input" name="login" autofocus="autofocus" autocomplete="username" id="aaaaa">
You must to do that after your WebBrowser have finished to load the document. A little example below:
WebBrowser1.ScriptErrorsSuppressed = True
WebBrowser1.Navigate("https://html.com/tags/input/")
AddHandler WebBrowser1.DocumentCompleted, Sub(senderObj As Object, eObj As WebBrowserDocumentCompletedEventArgs)
Dim inputs As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
If inputs IsNot Nothing AndAlso inputs.Count > 0 Then
For Each current As HtmlElement In inputs
current.SetAttribute("value", "Eurekaaaaaaaaaaaaaaaaaaaaa")
Next
End If
End Sub

Get the text inside <font> tags VB.NET

Hey guys i just started coding using Visual Basics and i just can't seem to figure out how to get the text inside a <font> and <b>
I am using the built in web browser in Visual Basics
The HTML page contains
<font size="1"><b>Bob</b></font>
I have tried
Dim theElementCollection As HtmlElementCollection = Nothing
theElementCollection = WebBrowser1.Document.GetElementsByTagName("font")
For Each curElement As HtmlElement In theElementCollection
If InStr(curElement.GetAttribute("size").ToString, "1") Then
TextBox1.Text = curElement.InnerText
End If
Next
I want to get Bob and add it into a text box.
i researched regular expressions and parsing but couldn't understand anything since i'm new to vb :(
For anyone that has the same problem i solved it myself :)
Dim PageElements As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("font")
For Each CurElement As HtmlElement In PageElements
TextBox1.Text = CurElement.InnerText
Next
The code above works perfect!

Block a certain element in web browser Vb.net

I a wondering if and how you would be able to block a certain element in the webbrowser.
For example there is a certain element on a website:
<div class="btn" id="button" value="ClickMe"/>
Will you be able to block or hide that specific element in the webbrowser?
There might be a certain ad, iframe or whatever its called that might just be in the way?
Thanks for the help I appreciate it.
double click on webbrowser1 designer you should be in WebBrowser1_DocumentCompleted add this line
'selector by division id
webbrowser1.Document.getElementById("button").innerHtml = ""
'selector spesific element with spesific attribute
<input id="_authentication_token" name="_authentication_token" type="hidden" value="11740686"/>
dim mycol as htmlElementCollection = webbrowser1.document.getElementBytagname("input")
for each ele as Htmlelement in mycol
if (ele.getAttribute("value").tostring = "11740686") then ele.innerHtml = ""
next
for your exemple :
<div class="btn" id="button" value="ClickMe"/>
dim mycol as htmlElementCollection = webbrowser1.document.getElementBytagname("div")
for each ele as Htmlelement in mycol
if (ele.getAttribute("value").tostring = "ClickMe" and ele.getAttribute("id").tostring = "button" ) then ele.innerHtml = ""
next

How to click HTML button programatically by vb.net

I am trying to click a button programatically . The button is on the 3rd page of the website. and it does not have any id . It has just name , type and value . The HTML code of the button is given below
<FORM NAME='form1' METHOD='post' action='/dflogin.php'>
<INPUT TYPE='hidden' NAME='txtId' value='E712050-15'>
<INPUT TYPE='hidden'NAME='txtassId' value='1'>
<INPUT TYPE='hidden' NAME='txtPsw' value='HH29'>
<INPUT TYPE='hidden' NAME='txtLog' value='0'>
<h6 align='right'>
<INPUT TYPE='SUBMIT' NAME='btnSub' value='Next' style='background-color:#009900; color:#fff;'></h6></FORM>
I have tried these codes in vb.net 2008 express edition...
For Each webpageelement As HtmlElement In allelements
If webpageelement.GetAttribute("value") = "Next" Then
webpageelement.InvokeMember("click")
End If
Next
And 2nd one
theElementCollection = WebBrowser1.Document.GetElementsByTagName("INPUT")
For Each curElement As HtmlElement In theElementCollection
ctrlIdentity = curElement.GetAttribute("innerText").ToString
If ctrlIdentity = "Next" Then
curElement.InvokeMember("click")
End If
Next
and 3rd one is
Dim l_forms = WebBrowser1.Document.GetElementsByTagName("form")
If l_forms.Count > 0 Then
l_forms.Item(0).InvokeMember("submit")
End If
and 4th one is
Do While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
Loop
WebBrowser1.Document.Body.InnerHtml = Replace(WebBrowser1.Document.Body.InnerHtml,"NAME='btnSub'", "NAME='btnSub' id='btnSub'") 'insert id into youre button
WebBrowser1.Document.GetElementById("btnSub").InvokeMember("click") 'click on btnSub
and the last one is
Dim i As Integer
Dim allButtons As HtmlElementCollection
allButtons = WebBrowser1.Document.GetElementsByTagName("input")
i = 0
For Each webpageelement As HtmlElement In allButtons
i += 1
If i = 5 Then
webpageelement.InvokeMember("click")
End If
Next
These all codes are unable to click that button. Kindly Please Suggest a appropriate solution for clicking this button. Thank You So Much
something like this would be a server side JavaScript and jquery solution
string script = "$(document).ready(function() {$('input[name=btnSub]').trigger('click'); });";
ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", script, true);

get pictures fom webbrowser to picturebox

I am having a problem displaying some pictures (more than one) in a picturebox.
<div id="salary_total" style="display: block;"><table style="border: 3px solid rgb(71, 5, 6); padding-right: 1px;" bgcolor="#ffffff" cellpadding="0" cellspacing="0"><tbody><tr><td><img src="./images/counter/b.gif"></td>
<td><img src="./images/counter/3.gif" border="0"></td>
<td><img src="./images/counter/3.gif" border="0"></td>
<td><img src="./images/counter/0.gif" border="0"></td>
<td><img src="./images/counter/8.gif" border="0"></td>
</tr></tbody></table>
those picture links, shows like a number like 3308, and it changes every time the page loads. how can I display those pictures (next to each other) in a picturebox.
Try
Dim htmlDocument As HtmlDocument = Me.WebBrowser1.Document
Dim htmlElementCollection As HtmlElementCollection = htmlDocument.Images
For Each htmlElement As HtmlElement In htmlElementCollection
Dim imgUrl As String = htmlElement.GetAttribute("src")
If imgUrl.Contains("counter") Then
Me.PictureBox1.ImageLocation = imgUrl.Substring(0, 41)
End If
Next
This one works for the first picture, how can I have like 3 more pictureboxs, and do the same for the other 3 pictures?, like the 3.gif will go to the 1st picturebox, and so on?!
I figured it out: Here is the solution! Thanks
Try
Dim htmlDocument As HtmlDocument = Me.WebBrowser1.Document
Dim htmlElementCollection As HtmlElementCollection = htmlDocument.Images
Dim ImagesFound As Integer = 0
For Each htmlElement As HtmlElement In htmlElementCollection
Dim imgUrl As String = htmlElement.GetAttribute("src")
If imgUrl.Contains("counter") Then
ImagesFound+=1
Select Case ImagesFound
Case 1
PictureBox1.ImageLocation = imgUrl
Label1.Text = PictureBox1.ImageLocation.ToString()
Case 2
PictureBox2.ImageLocation = imgUrl
'... etc.
End Select
End If
Next
Catch ex As Exception
End Try
First, you ImageLocation will come out like this:
http://www.link.com./images/counter/8.gif
That's probably not what you intended.
Second, Shoban said that you should be using regular text and CSS. He's right.
Third, If you want to display multiple images in a single picturebox, you will need to make a single image object and draw the other images into it. There are VB.Net functions for that and also native Windows API (CopyRect?).
You can use multiple picture boxes if you like.