简体   繁体   中英

C# simulating onclick in webbrowser

I studied similar questions, but didn't find a working solution.

So, the question is how to invoke/run an onclick in webbrowser.

If the code is like this:

<div class="fl_r">
<div class="delete_post">
<div id="delete_post-23304691_11" onclick="wall.deletePost('-23304691_11', '62c2b8dca377d231af');" onmouseover="wall.activeDeletePost('-23304691_11', 'Удалить запись')" onmouseout="wall.deactiveDeletePost('-23304691_11')"></div>

I use:

HtmlElement el = webBrowser1.Document.All["delete_post-23304691_11"];
el.InvokeMember("onclick");

And it works perfectly.

But i also have other code:

<div class="info_footer">
<span class="fl_r actions" id="actions-23304691_12"><a onclick="wall.deletePost('-23304691_12', '58ddeb8beaaceb4f2c');">Delete</a></span>
today at 0:52 
</div>

And the previous variant is not working here. How do I invoke that onlick?

The onclick is assigned to a, not span, this should work..

HtmlElement el = webBrowser1.Document.All["actions-23304691_12"].Children[0];
el.InvokeMember("onclick");

You can also give the a tag a unique id and invoke that instead (better approach IMHO).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM