【问题标题】:WebBrowser Control - Invoke Script Problems with JavaScript ButtonWebBrowser 控件 - 使用 JavaScript 按钮调用脚本问题
【发布时间】:2012-06-15 14:12:59
【问题描述】:

我正在尝试登录网站。我能够使用所有连接信息正确填写表格,但我无法登录页面。该按钮是一个没有名称或ID的链接,所以我无法直接单击它。我一直在研究 invokeScript() 的东西,但这似乎也不起作用。这是按钮代码:

<div style="float:left; width:50px; margin: 0px auto 0px auto; text-align:center;">
    <div id="loginBtn">
        <a href="#" style="text-decoration:none; font-weight:bold; font-size: 10px; color:#FFFFFF;" onClick="javascript: LoginSubmit(event, true);" tabindex="3">
            Log In
        </a>
    </div>
</div>

我怎样才能点击这样的链接?

我试过这样的东西:

webBrowserControl.InvokeScript("LoginSubmit", "true" );

webBrowserControl.InvokeScript("LoginSubmit(event, true)"); 

webBrowserControl.InvokeScript("LoginSubmit", new object[] { new string[] { "event", "true" } });

【问题讨论】:

  • 这个问题甚至不包括什么是(是)错误。谷歌搜索时没有用。

标签: c# javascript wpf-controls webbrowser-control invokescript


【解决方案1】:

您可能缺少文档,如下所示:

webBrowserControl.Document.InvokeScript(name, args)

如果不尝试使用this wrapper method 调用脚本,请提取:

private object MyInvokeScript(string name, params object[] args) 
{ 
    return webBrowserControl.Document.InvokeScript(name, args); 
}

…

int x = 50; 
int y = 100; 
MyInvokeScript("LoginSubmit",x, y);

【讨论】:

  • 这行得通,但方法中没有 .Document。我不得不去 webBrowserControl.InvokeScript。不过我已经登录了,这很好!
  • 好东西,很高兴能帮上忙
  • 好的,谢谢。稍后我会接受答案。现在还为时过早。不过你已经收到了我的 +1。
  • 不错的答案,但他明确指出他使用的是 WPF 浏览器,因此很明显InvokeScript 方法之前没有.Document 成员。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-13
  • 2013-10-12
  • 1970-01-01
  • 2013-12-25
  • 1970-01-01
  • 2012-09-10
相关资源
最近更新 更多