Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2567
  • Last Modified:

VB.NET webbrowser Span Class CLICK

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
MrReplica
Asked:
MrReplica
  • 8
  • 6
  • 2
1 Solution
 
Luis PérezSoftware Architect in .NetCommented:
Sorry, but... what link? That's a span.
0
 
MrReplicaAuthor Commented:
ok.span.but i need to click it
0
 
mohammad827Commented:
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
MrReplicaAuthor Commented:
i don't need to open a  new page.i need only click this span with a button in my application.
0
 
mohammad827Commented:
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
 
mohammad827Commented:
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
 
Luis PérezSoftware Architect in .NetCommented:
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
 
MrReplicaAuthor Commented:
sorry,but it doesn't has any Id
it's all
<span class="mceEditorOff">HTML-edit</span>

Open in new window

0
 
mohammad827Commented:
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
 
MrReplicaAuthor 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
0
 
mohammad827Commented:
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
 
MrReplicaAuthor Commented:
can u please translate ur code in VB.NET ?
0
 
MrReplicaAuthor Commented:
UP
0
 
MrReplicaAuthor Commented:
UPPPPPPPP
0
 
mohammad827Commented:
Sorry can't convert to VB.Net. It is logical so you shud be able to do it if you want.
0
 
MrReplicaAuthor Commented:
not vb.net
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 8
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now