开发者

finding which form the input field belongs to delphi

Follow my previous question开发者_Python百科 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,'test@gmail.com');

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?


fld.form points to the form the element belongs to. You can use doc.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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜