1

In a regular WebBrowser you can click something with this code:

webBrowser1.Document.GetElementById("welcome_box_sign_in_button").InvokeMember("Click");

But in a WebKitBrowser, there is no .InvokeMember. How do I go about doing this?

This is the code for the button I am trying to click:

<input tabindex="5" class="submit spriteall spritesite" id="welcome_box_sign_in_button" onclick="try{}catch(e){};if(!this.elem_welcome_box_sign_in_button){this.elem_welcome_box_sign_in_button=$('welcome_box_sign_in_button');this.spin_welcome_box_sign_in_button=$('welcome_box_sign_in_button_spinner');this.restore=function(t){return function(){t.elem_welcome_box_sign_in_button.show();t.spin_welcome_box_sign_in_button.hide();Event.stopObserving(window, 'unload', t.restore);}}(this);}this.elem_welcome_box_sign_in_button.hide();this.spin_welcome_box_sign_in_button.show();Event.observe(window, 'unload', this.restore);" type="submit" value="Sign In">
Dozer789
  • 1,980
  • 2
  • 23
  • 43

2 Answers2

1

I have answered similar question at How to click on a link using Webkit Browser?. And I don't work with Windows and all my experience is on Webkit GTK. Following comments are based on that experience.

Moreover, this is just detailed clarification of answer by gretro.

If your webkit implementation is not supporting DOM APIs, then you can use javascript execution to do lot of work.

Using javascript execution then you can do most, if not all the DOM operations. The API functions are usually same as javascript functions and most of the time call exact same functions internally despite of origination. Communication between your application and javascript can be little challenging, but if you can read alert messages, that also can be solved. It looks like this library does support alert handling mechanism. A tool I wrote at https://github.com/nhrdl/notesMD will show some examples of achieving this communication, though it uses GTK version and is written in python.

Gretro's answer can done as follows. Please watch out for syntax errors as I have not tested this because of lack of access to .NET world. In my experience, statement ending ";" is required by some implementations when executing like this, some complain and some don't care. So that's another thing to watch out for.

browser.Document.InvokeScriptMethod("document.getElementById('<id>').click()", new object[]{});
Community
  • 1
  • 1
user871199
  • 1,420
  • 19
  • 28
0

You could always append a script to the DOM and call it with the InvokeScript method. You could pass the id of the DOM element along with the name of the action to trigger and have Javascript do the rest.

browser.Document.InvokeScriptMethod("functionName", new object[]{"parameter1", "parameter2"});

http://webkitdotnet.sourceforge.net/docs/html/M_WebKit_DOM_Document_InvokeScriptMethod.htm

gretro
  • 1,934
  • 15
  • 25
  • I don't really know how to use your code. I have edited my post, so could you edit your code for my post? Thanks. – Dozer789 Mar 03 '14 at 17:33