VB.NET webbrowser Span Class CLICK

MrReplica
MrReplica used Ask the Experts™
on
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?????
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Luis PérezSoftware Architect in .Net

Commented:
Sorry, but... what link? That's a span.

Author

Commented:
ok.span.but i need to click it
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

C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Author

Commented:
i don't need to open a  new page.i need only click this span with a button in my application.
Well then
<span id="myspan" class="mceEditorOff">HTML-edit</span>
<script>
function calledByButton(){
var mySpn = document.getElementById('mySpan');
mySpan.click();
}

Open in new window

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

Luis PérezSoftware Architect in .Net

Commented:
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.

Author

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

Open in new window

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

Author

Commented:
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
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.

Author

Commented:
can u please translate ur code in VB.NET ?

Author

Commented:
UP

Author

Commented:
UPPPPPPPP
Sorry can't convert to VB.Net. It is logical so you shud be able to do it if you want.

Author

Commented:
not vb.net

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial