C# WebBrowser 控件中输入标签的设置值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14681335/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting Value of an Input Tag in WebBrowser Control
提问by Runewake2
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.
我试图帮助用户使用自定义控件登录他们的帐户WebBrowser
。我正在尝试使用WebBrowser
'sInvokeScript
函数将输入标签的值设置为玩家用户名。但是,我当前的解决方案只是渲染一个空白的白页。
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 Phone 上执行此操作,因此我在此处和其他地方找到的许多示例将无法使用,因为我无法访问相同的功能。
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.
编辑:也许我不清楚,但我正在使用 Windows Phone,它具有有限的可用 API,这意味着我无法访问该Document
属性和许多其他功能。我确实可以访问InvokeScript
,但仅此而已。
回答by Dimitris Sapikas
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/