Solved

VB.NET webbrowser Span Class CLICK

Posted on 2011-09-02
16
2,098 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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
 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

773 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