Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
hello guys , here a code that`s contains a button i need to click but i can`t do it although i tried many way to do it using
C#
currentwb.Document.GetElementById

but as we see this code have no id for the element ,,
C#
<a class="single_like_button btn3-wrap"  önclick="openWin_1083724();">
						                    <span> </span><div class="btn3">Click Here</div></a>


so any suggestion about how i can get this element is clicked ?
Posted
Updated 16-May-20 17:44pm
v2

You can't click on it? This makes no sense to me. You want to trigger the click event on the element from javascript? Try this: http://www.nonobtrusive.com/2011/11/29/programatically-fire-crossbrowser-click-event-with-javascript/[^]

[Update]
If you want to automate IE, you better use this approach: http://harness.codeplex.com/[^]

If you stick to WebBrowser control (currentwb), try this approach:

C#
HtmlElement link = currentwb.Document.GetElementByID("id_of_element")
link.InvokeMember("Click")


Or, if you can't assign id for some reason, you can use this approach.
C#
HtmlElementCollection links = currentwb.Document.GetElementsByTagName("A");

foreach (HtmlElement link in links)
{
    if (link.InnerText.Equals("Link text"))
        link.InvokeMember("Click");
}

Be aware to put in the IF statement the proper condition to identify your link.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 3-Nov-13 15:50pm    
I would rather agree with "This makes no sense...". Using fireClick you refer to is possible, but usually not needed. Please see my answer.
—SA
Zoltán Zörgő 3-Nov-13 16:26pm    
True. Not needed in general, and this code snippet does not require it either. But who knows what the final purpose of OP is... sounds like horse, smells like horse, looks like a horse... but might be a zebra though :)
Sergey Alexandrovich Kryukov 3-Nov-13 16:41pm    
This is only because Zebra is actually the horse (equus), not "like a horse" ... :-)
—SA
Ali Al-Masry 4-Nov-13 7:51am    
how i use this Java code while i am doing that in C# ?
Zoltán Zörgő 4-Nov-13 8:02am    
1) It was Javascript, not Java
2) See update. Note, that GetElementById needs an ID to work with, your element has no id.
"Click" is something which you do with a mouse or, in fact, with a keyboard. If you think about it, you will understand that what you need is not a click. You simply want to have "the same effect as the user's click on the element". In other works, you simply need to call openWin_1083724() from your JavaScript.

—SA
 
Share this answer
 
Comments
Ali Al-Masry 4-Nov-13 7:52am    
right , show me how with a example please .. i have no idea about how to run or add java script to C# ???
Sergey Alexandrovich Kryukov 4-Nov-13 9:37am    
Example? Sure:

function clickBtn3() { openWin_1083724(); }

Only never give things such names, with numbers, etc. All names should be semantic.

Now what "java scripts"?! There is no such thing. Java is not a scripting language. If you mean JavaScript, it is something totally unrelated to Java. "Run or add JavaScript to C#"?! Look, it shows that you should first learn how 1) Web works, 2) what ASP.NET does and how it works, and so on. Right now you have no a clue. You need to learn it first, and this is not a matter of a Quick Answer.

In brief, ASP.NET works only on the server part. You use C# or other language to get HTTP request and generate HTTP response. The response can include anything (it is defined by its content type), including JavaScript. A browser on a client side receives HTTP response and processes it, in particular, it can run JavaScript. And then you need to learn how to make JavaScript working. So, you need to learn at least some JavaScript.

Are you getting the idea?

—SA
i have a question how to click on add child option in span
give ma code


[CODE REMOVED BECAUSE IT IS SCREWING UP PAGE FORMATTING]
 
Share this answer
 
v2
Comments
Dave Kreskowiak 17-May-20 0:20am    
Posting your question as an ANSWER to an old question is a bad idea.

Go to the "quick answers" menu and click "Ask a question".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900