[英]Setting Value of an Input Tag in WebBrowser Control
I am attempting to help a user log into their account using a custom WebBrowser
control.我试图帮助用户使用自定义WebBrowser
控件登录到他们的帐户。 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.我正在尝试使用WebBrowser
的InvokeScript
function 将输入标签的值设置为玩家用户名。但是,我当前的解决方案只是呈现一个空白页面。
My current code looks like this (web is the name for my WebBrowser
control):我当前的代码如下所示(web 是我的WebBrowser
控件的名称):
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.我正尝试在 Windows 电话上执行此操作,因此我在此处和其他地方找到的许多示例将无法使用,因为我无权访问相同的功能。
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.编辑:也许我不清楚,但我正在使用 Windows Phone,它的可用 API 有限,这意味着我无权访问Document
属性和许多其他功能。 I do have access to InvokeScript
, but not much more.我确实可以访问InvokeScript
,但仅此而已。
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/ 你可以在这里找到更多: http : //deltahacker.gr/2011/08/15/ftiakste-to-diko-sas-robot/
It's been along time since this question is posted but I think I'll post an answer to this so that it will help some one who came across the same situation这个问题发布已经有一段时间了,但我想我会发布一个答案,这样它会帮助遇到同样情况的人
try
{
webBrowser1.Document.GetElementById("navbar_username").SetAttribute("value", "your user");
webBrowser1.Document.GetElementById("navbar_password").SetAttribute("value", "your pass");
webBrowser1.Document.GetElementById("Log in").InvokeMember("click");
}
catch { }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.