Solved

VB.NET webbrowser Span Class CLICK

Posted on 2011-09-02
16
2,245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 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