WebBrowser 控件中输入标签的设置值 [英] Setting Value of an Input Tag in WebBrowser Control

查看:22
本文介绍了WebBrowser 控件中输入标签的设置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用自定义 WebBrowser 控件帮助用户登录其帐户.我正在尝试使用 WebBrowserInvokeScript 函数将输入标签的值设置为玩家用户名.但是,我目前的解决方案只是渲染一个空白的白页.

I am attempting to help a user log into their account using a custom WebBrowser control. I am trying to set the value of an input tag to the players username using the WebBrowser's InvokeScript function. However, my current solution is doing nothing but rendering a blank white page.

我当前的代码如下所示(web 是我的 WebBrowser 控件的名称):

My current code looks like this (web is the name for my WebBrowser control):

web.Navigate(CurrentURL, null, @"<script type='text/javascript'>
    function SetPlayerData(input) {
        username.value = input;
        return true;
    }
</script>");
web.Navigated += (o, e) =>
{
    web.IsScriptEnabled = true;
    web.InvokeScript("SetPlayerData", @"test");
};

如前所述,这现在不起作用.我正在尝试在 Windows Phone 上执行此操作,因此我在此处和其他地方找到的许多示例将无法使用,因为我无法访问相同的功能.

As mentioned, this does not work right now. I am attempting to do this on Windows Phone so a number of the example's I have found here and in other places will not work as I do not have access to the same functions.

我将如何成功执行此操作?

How would I perform this successfully?

也许我不清楚,但我正在使用 Windows Phone,它具有有限的 API,这意味着我无法访问 Document 属性和许多其他功能.我确实可以访问 InvokeScript,但仅此而已.

Perhaps I was not clear, but I am working with Windows Phone, which has a limited API available meaning I do not have access to the Document property and a number of other functions. I do have access to InvokeScript, but not much more.

推荐答案

webBrowser1.Document.GetElementById("navbar_username").InnerText ="Tester";
webBrowser1.Document.GetElementById("navbar_password").InnerText = "xxxxxxxxxxx";

foreach (HtmlElement HtmlElement1 in webBrowser1.Document.Body.All)
    {
    if (HtmlElement1.GetAttribute("value") == "Log in")
        {
        HtmlElement1.InvokeMember("click");
        break;
        }
    }

您可以在这里找到更多信息:http://deltahacker.gr/2011/08/15/ftiakste-to-diko-sas-robot/

you may find more here : http://deltahacker.gr/2011/08/15/ftiakste-to-diko-sas-robot/

这篇关于WebBrowser 控件中输入标签的设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆