[英]web page doesn't recognize text has been entered in textbox
So I'm setting the value of a textbox, then I'll click a button to submit the search. 因此,我要设置文本框的值,然后单击一个按钮以提交搜索。 The value in the textbox is showing what I want, but when I trigger the click of the button, the website gives me an error message on the page as if the textbox value is empty (even though I'm looking at it and it's showing what I wanted).
文本框中的值显示了我想要的内容,但是当我单击按钮时,网站在页面上向我显示一条错误消息,好像文本框的值是空的(即使我正在查看并且它还在显示)我想要的)。
Now if I manually click on the button, it still thinks the textbox is empty. 现在,如果我手动单击按钮,它仍然认为文本框为空。 But if I manually click on the textbox (just click, don't change anything), then manually click on the button, it works.
但是,如果我手动单击该文本框(只需单击,不要更改任何内容),然后手动单击该按钮,它将起作用。
So apparently there's something happening behind the scenes that requires the textbox to have had the focus before the page will recognize what's been typed in. 因此,显然在幕后发生了一些事情,要求文本框具有焦点,然后页面才能识别出所键入的内容。
private void SetText(string elementID, string text)
{
foreach (HtmlWindow hw in this.webBrowser1.Document.Window.Frames)
{
HtmlElement element = hw.Document.GetElementById(elementID);
if (element != null)
{
element.SetAttribute("value", text);
// here's where I'm trying things
break;
}
}
}
Here's what I've tried (not sure all of these were even valid things, but I tried them anyway: 这是我尝试过的方法(不确定所有这些方法是否都是有效的方法,但无论如何我还是尝试了它们:
I've tried setting the focus on the textbox and then removing it by setting it on the button -- element.Focus() and then button.Focus() before clicking the button. 我尝试将焦点设置在文本框上,然后通过在按钮上设置它(元素.Focus(),然后是button.Focus())来删除它,然后再单击按钮。
I've tried invoking the changed event -- element.InvokeMember("change"), element.InvokeMember("changed"), element.InvokeMember("onchange"), element.InvokeMember("textchanged"). 我尝试调用更改后的事件-element.InvokeMember(“ change”),element.InvokeMember(“ changed”),element.InvokeMember(“ onchange”),element.InvokeMember(“ textchanged”)。
I've tried invoking the focus event -- element.InvokeMember("focus"). 我尝试调用焦点事件-element.InvokeMember(“ focus”)。
I've tried invoking the lostfocus event -- element.InvokeMember("lostfocus"). 我尝试调用lostfocus事件-element.InvokeMember(“ lostfocus”)。
I have no idea what it is that the webpage is expecting to be triggered when someone actually types into the textbox, but it's apparently preventing the page from "seeing" what's been placed in there by my code. 我不知道当有人实际在文本框中键入内容时,网页会被触发,但这显然阻止了该页面“看到”我的代码所放置的内容。
Any ideas? 有任何想法吗?
Turns out there were 3 textboxes (each with a slightly different name) that are somehow interconnected. 原来,有3个文本框(每个框的名称略有不同)相互连接。 The value of all 3 must be set before the button will work properly.
必须先设置所有3个值,然后按钮才能正常工作。 I thought I'd tried that, but perhaps I didn't do all 3 before, or maybe I had them in the wrong order.
我以为我已经尝试过了,但是也许我之前没有做过全部三件事,或者我的顺序错了。 Ugh.
啊。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.