查找输入字段属于delphi的哪个表单
按照我之前的问题,我自己设法回答了。我能够将文本放置在 Delphi 应用程序中的网络浏览器上提供的网站的输入字段中。有时一个网站上有多种表单,大多数时候大约有 2 个,但也可能会不少。现在我的问题是。我如何“测试”或找出所选输入字段属于哪种形式。让我们举个例子。例如,gmail.com 有 2 个输入字段:“电子邮件”和“密码” 我也知道该网站上有 2 个表单。使用这样的代码,您可以选择其中之一:
doc:=webbrowser1.Document as IHTMLDocument2;
frm:=doc.forms.item(0,EmptyParam) as IHTMLFormElement;
fld:=frm.item('Email',EmptyParam) as IHTMLInputTextElement;
fld.value:=GetFieldValue(theForm,'[email protected]');
通过将第二行中的 0 更改为 1,您将在网站上获得第二个表单。现在我想知道如何让程序自己找出输入字段也属于哪种形式。你能尝试一下吗?或者其他什么?大家有什么想法吗?
Follow my previous question which i managed to answer myself. I am able to place text in an input field on a website served on webbrowser in a delphi application. sometimes there are multiple forms on a website, most of the time its around 2, but it could head up to a faire few. Now my question is. How can I 'test' or find out which form the selected input field belongs. Lets just take an example. For example, gmail.com there are 2 input fields: 'Email' and 'Passwd' I also know that there are 2 forms on this site. with code like this one you can select either one of them :
doc:=webbrowser1.Document as IHTMLDocument2;
frm:=doc.forms.item(0,EmptyParam) as IHTMLFormElement;
fld:=frm.item('Email',EmptyParam) as IHTMLInputTextElement;
fld.value:=GetFieldValue(theForm,'[email protected]');
by changing the 0 to a 1 in the second line you have the second form on the site. Now I want to know how can I let the program find out for itself which form the input field belongs too. could you do this with try? or anything else? Any have any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
fld.form
指向元素所属的表单。您可以使用 doc.getElementFromId 或您喜欢的任何其他方法来获取元素,而无需使用表单来获取它,尽管如果它有 id,则最简单。另一种选择是搜索所有表单以检查它是否具有给定名称的字段,但如果字段存在于多个表单中,则这对您没有帮助。
fld.form
points to the form the element belongs to. You can usedoc.getElementFromId
or any other method you like to get the element without using the form to get it, although it is easiest if it has an id.Other option is to search through all forms to check if it has a field with the given name, but that won't help you if a field exists in more than one form.