Solved

VB.NET webbrowser Span Class CLICK

Posted on 2011-09-02
16
2,018 Views
Last Modified: 2012-05-12
Hi all.
On webform i have this link
<span class="mceEditorOff">HTML-edit</span>

Open in new window


How i can click this link using webbrowser and button?????
0
Comment
Question by:MrReplica
  • 8
  • 6
  • 2
16 Comments
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 36472508
Sorry, but... what link? That's a span.
0
 

Author Comment

by:MrReplica
ID: 36472512
ok.span.but i need to click it
0
 
LVL 4

Expert Comment

by:mohammad827
ID: 36472513
First it is not a link. It is just some text displayed. If you want click on it then do following
<span class="mceEditorOff" onclick="gotoPage()">HTML-edit</span>
<script>
function gotoPage(){
window.location.href='some url';
}
</script>

Open in new window

0
 

Author Comment

by:MrReplica
ID: 36472551
i don't need to open a  new page.i need only click this span with a button in my application.
0
 
LVL 4

Expert Comment

by:mohammad827
ID: 36472566
Well then
<span id="myspan" class="mceEditorOff">HTML-edit</span>
<script>
function calledByButton(){
var mySpn = document.getElementById('mySpan');
mySpan.click();
}

Open in new window

0
 
LVL 4

Expert Comment

by:mohammad827
ID: 36472575
or Something like this
// invoke fireEvent() on object whose ID is passed as parameter
function doFire(objID) {
    var newEvt = document.createEventObject()
    newEvt.button = 3
    document.all(objID).fireEvent("onclick", newEvt)
    // don't let button clicks bubble
    event.cancelBubble = true
}

Open in new window

0
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 36472602
Ok.

First of all, you need to give your span a ID:
<span id="mySpan" class="mceEditorOff">HTML-edit</span>

You can perform a virtual click via webBrowser this way:
Me.WebBrowser1.Document.GetElementById("mySpan").InvokeMember("click")

Hope that helps.
0
 

Author Comment

by:MrReplica
ID: 36472844
sorry,but it doesn't has any Id
it's all
<span class="mceEditorOff">HTML-edit</span>

Open in new window

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 4

Accepted Solution

by:
mohammad827 earned 500 total points
ID: 36472919
Well then u need find the element by attribute name and value. Something like this has to be called from button click
function getMySpanByClass(){
    var arrElements = document.getElementsByTagName('span');
	var oCurrent;
	for(var i=0; i<arrElements.length; i++){
	    oCurrent = arrElements[i];
	    oAttribute = oCurrent.getAttribute("class");
		if("mceEditorOff" == oCurrent.className){
			oCurrent.click();
			break;
		}
	}
}

Open in new window

0
 

Author Comment

by:MrReplica
ID: 36472938
i have just tryed this
 Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim A As Integer = NumericUpDown1.Value
        Dim doc1 = WebBrowser1.Document
        doc1.GetElementsByTagName("SPAN")(A).InvokeMember("click")
    End Sub

Open in new window

it's working,but the value il always different
0
 
LVL 4

Expert Comment

by:mohammad827
ID: 36472997
You code does not guarantee which span would be returned. There could be multiple SPAN tag in the page. Unles you ensure that the SPAN tags are rendered exactly same as your drop-down member count.
0
 

Author Comment

by:MrReplica
ID: 36473018
can u please translate ur code in VB.NET ?
0
 

Author Comment

by:MrReplica
ID: 36478704
UP
0
 

Author Comment

by:MrReplica
ID: 36518606
UPPPPPPPP
0
 
LVL 4

Expert Comment

by:mohammad827
ID: 36521112
Sorry can't convert to VB.Net. It is logical so you shud be able to do it if you want.
0
 

Author Closing Comment

by:MrReplica
ID: 36967582
not vb.net
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now