Hack Forums
[.NET] [VB.NET] Click button without ID (WebBrowser Control) [VB.NET] - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] [VB.NET] Click button without ID (WebBrowser Control) [VB.NET] (/showthread.php?tid=506467)

Pages: Pages 1 2


[VB.NET] Click button without ID (WebBrowser Control) [VB.NET] - H3x0S - Jun 27, 2010

I saw that many people can't find a way to click a button without ID in WebBrowser control, so here is a solution! 🤗
I've created a function that will do that!

Code
'Author: H3x0S
'Release Date: June/27/2010

Public Function ClickWBElement(ByVal TagName As String, ByVal Attribute As String, ByVal AttributeContains As String)
  Dim ElCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName(TagName)
  For Each Element As HtmlElement In ElCollection
    If Element.GetAttribute(Attribute).Contains(AttributeContains) Then
    Element.InvokeMember("click")
    End If
  Next
  ClickWBElement = True
    End Function

Usage:

Code
ClickWBElement("BUTTON", "ATRIBUTE", "ATRIBUTETEXT")

Explanation:

Let's say that you have a button that doesn't have an ID.
Button code is:

Code
<button class="login">LOGIN</button>


You would use this function like this:

Code
ClickWBElement("button", "class", "login")

Thanks to Eleqtriq for inspiration.

PLEASE GIVE CREDITS IF USED!



* - DarkSeven46 - Jun 27, 2010

Nice Function. +rep for you.


* - H3x0S - Jun 27, 2010

(Jun 27, 2010 12:08 PM)DarkSeven46 Wrote:  Nice Function. +rep for you.

Thank you. I am in a good mood today. 🙂


* - HackFox - Jun 27, 2010

bookmared Was searching for this :)


* - H3x0S - Jun 27, 2010

(Jun 27, 2010 12:17 PM)HackFox Wrote:  *bookmared* Was searching for this :)

I saw many threads about this. That is why I created this function.


* - DarkSeven46 - Jun 27, 2010

(Jun 27, 2010 12:18 PM)H3x0S Wrote:  I saw many threads about this. That is why I created this function.

I created a gmail function. where instead of having to change the code. It works like this, as a function:

Code
GmailSend("[email protected]", "Password", "[email protected]", "Subject", "Message")

And a test function:

Code
GmailTest("[email protected]", "Password")



* - H3x0S - Jun 27, 2010


Where is the function? That is just a usage. 🙂
Make a thread about it.


* - 50GTB - Jun 27, 2010

awsome i will check this soon i finish my logger


* - Modesty - Jun 27, 2010

nice one dude, i remmeber when i had this problem with an old program of mine, and i did something similar, but it was way longer code than this,yours seems much more efficient! nice one, kudos to you


* - DarkSeven46 - Jun 27, 2010

(Jun 27, 2010 12:29 PM)H3x0S Wrote:  Where is the function? That is just a usage. 🙂
Make a thread about it.

Ok, I will call it Gmail Functions.


* - H3x0S - Jun 27, 2010

(Jun 27, 2010 12:34 PM)DarkSeven46 Wrote:  Ok, I will call it Gmail Functions.

Yea, that is good. Functions FTW.


* - DarkSeven46 - Jun 27, 2010

(Jun 27, 2010 12:42 PM)H3x0S Wrote:  Yea, that is good. Functions FTW.

Ok made thread. I think its above you thread, wait never mind. Its below you thread.


* - H3x0S - Jun 27, 2010

BumpBumpBumpBumpBumpBump!


* - Fake. - Jun 28, 2010

Funny if there are two or more buttons VERY similar ~
But interesting code anyhow.


* - H3x0S - Jun 28, 2010

(Jun 28, 2010 04:53 AM)jacktheripper Wrote:  Funny if there are two or more buttons VERY similar ~
But interesting code anyhow.

Thank you. This is very useful function.