Setting Value of an Input Tag in WebBrowser Control

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-11 04:48:05

问题


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.

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");
};

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?

EDIT: 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.


回答1:


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;
        }
    }

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



来源:https://stackoverflow.com/questions/14681335/setting-value-of-an-input-tag-in-webbrowser-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!