简体   繁体   English

您如何使用WebKitBrowser调用会员?

[英]How do you InvokeMember with WebKitBrowser?

In a regular WebBrowser you can click something with this code: 在常规的WebBrowser您可以使用以下代码单击某些内容:

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

But in a WebKitBrowser, there is no .InvokeMember . 但是在WebKitBrowser中,没有.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">

I have answered similar question at How to click on a link using Webkit Browser? 我已经在如何使用Webkit浏览器单击链接上回答了类似的问题 . And I don't work with Windows and all my experience is on Webkit GTK. 而且我不使用Windows,我的所有经验都是在Webkit GTK上进行的。 Following comments are based on that experience. 以下评论基于该经验。

Moreover, this is just detailed clarification of answer by gretro. 此外,这只是gretro答案的详细说明。

If your webkit implementation is not supporting DOM APIs, then you can use javascript execution to do lot of work. 如果您的Webkit实现不支持DOM API,则可以使用javascript执行大量工作。

Using javascript execution then you can do most, if not all the DOM operations. 使用javascript执行,您可以执行大部分(如果不是全部)DOM操作。 The API functions are usually same as javascript functions and most of the time call exact same functions internally despite of origination. API函数通常与javascript函数相同,并且大多数时候内部都会调用完全相同的函数,尽管有起源。 Communication between your application and javascript can be little challenging, but if you can read alert messages, that also can be solved. 您的应用程序和javascript之间的通信可能没有什么挑战,但是如果您可以阅读警报消息,那也可以解决。 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. 我在https://github.com/nhrdl/notesMD上编写的工具将显示实现此通信的一些示例,尽管该工具使用GTK版本并且是用python编写的。

Gretro's answer can done as follows. Gretro的答案可以做到如下。 Please watch out for syntax errors as I have not tested this because of lack of access to .NET world. 请注意语法错误,因为由于缺乏对.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[]{});

You could always append a script to the DOM and call it with the InvokeScript method. 您总是可以将脚本附加到DOM并使用InvokeScript方法进行调用。 You could pass the id of the DOM element along with the name of the action to trigger and have Javascript do the rest. 您可以传递DOM元素的ID以及要触发的操作名称,然后让Javascript完成其余的操作。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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