1

在常规WebBrowser中,您可以使用以下代码单击某些内容:

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

但是在 WebKitBrowser 中,没有.InvokeMember. 我该怎么做呢?

这是我要单击的按钮的代码:

<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">
4

2 回答 2

1

我已经在如何使用 Webkit 浏览器点击链接中回答了类似的问题?. 而且我不使用 Windows,我所有的经验都在 Webkit GTK 上。以下评论基于该经验。

而且,这只是gretro对答案的详细说明。

如果您的 webkit 实现不支持 DOM API,那么您可以使用 javascript 执行来完成大量工作。

如果不是所有的 DOM 操作,那么您可以使用 javascript 执行来完成大部分操作。API 函数通常与 javascript 函数相同,并且大部分时间在内部调用完全相同的函数,尽管它们的起源无关。您的应用程序和 javascript 之间的通信可能没什么挑战性,但如果您可以阅读警报消息,那也可以解决。看起来这个库确实支持警报处理机制。我在https://github.com/nhrdl/notesMD上编写的一个工具将展示一些实现这种通信的示例,尽管它使用 GTK 版本并且是用 python 编写的。

格雷特罗的回答可以按如下方式完成。请注意语法错误,因为由于无法访问 .NET 世界,我没有对此进行测试。根据我的经验,以“;”结尾的语句 像这样执行时某些实现需要,有些抱怨有些不在乎。所以这是另一件需要注意的事情。

browser.Document.InvokeScriptMethod("document.getElementById('<id>').click()", new object[]{});
于 2014-03-03T19:11:38.730 回答
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

于 2014-03-03T17:24:57.227 回答