Delphi 德尔福韦伯罗辛酒店
我想自动化以下过程: 我登录到一个网站。 在搜索页面上,输入要搜索的信息,然后单击搜索按钮。 单击将加载我的结果。 在生成的页面中,我选择预览pdf文件的选项,然后单击按钮。 单击此按钮可上载我的pdf文件 如果我将这些命令拆分为按钮,然后一个接一个地按下,一切都正常,但是当我想执行一行中的所有命令时,我得到了一个错误。(我认为错误是因为WebBrowser没有加载所有内容。)请帮助Delphi 德尔福韦伯罗辛酒店,delphi,twebbrowser,Delphi,Twebbrowser,我想自动化以下过程: 我登录到一个网站。 在搜索页面上,输入要搜索的信息,然后单击搜索按钮。 单击将加载我的结果。 在生成的页面中,我选择预览pdf文件的选项,然后单击按钮。 单击此按钮可上载我的pdf文件 如果我将这些命令拆分为按钮,然后一个接一个地按下,一切都正常,但是当我想执行一行中的所有命令时,我得到了一个错误。(我认为错误是因为WebBrowser没有加载所有内容。)请帮助 procedure TMainForm.Button10Click(Sender: TObject); var
procedure TMainForm.Button10Click(Sender: TObject);
var doc :IHTMLDocument2;
FileStream: TFileStream;
StreamAdapter: IStream;
PersistStreamInit: IPersistStreamInit;
i, a, b : integer;
sir: string;
MergiInainte:boolean;'
begin
MergiInainte:=false;
WebBrowser1.Navigate('https://website/externallogin.aspx');'
repeat
if ((WebBrowser1.ReadyState = READYSTATE_COMPLETE) and (WebBrowser1.Busy = false)) then
MergiInainte:=true;
until MergiInainte;' // This repeat is not working. Dont know why?
//After webBrowser is fully loaded, the next code has to be run
doc := WebBrowser1.Document AS IHTMLDocument2;
WebFormSetFieldValue(doc,0,'txtNume','user');
WebFormSetFieldValue(doc,0,'txtPwd','psswd');
WebBrowser1.OleObject.Document.GetElementByID('tibAutentification').click;'
//after the above code is fully executat, next code is in line
WebBrowser1.Navigate('https://website/Pages/SearchTitle.aspx');
//after the above code is executed, next i need to complete form element with what the nexd data
doc := WebBrowser1.Document AS IHTMLDocument2;
WebBrowser1.OleObject.Document.GetElementByID('chkTitleNo').click;
WebFormSetFieldValue(doc,0,'txtTitleNo','28972'); //nr titlu de proprietate
WebBrowser1.OleObject.Document.GetElementByID('tibSearch').click;
WebBrowser1.OleObject.Document.GetElementByID('fdgMain:_ctl3:imbView').click;
WebBrowser1.OleObject.Document.GetElementByID('tibViewPDF').click;
end;
// But i'm getting error: Access violation....read of adress 0000000.'
procedure TForm1.WebFormSetFieldValue(const document: IHTMLDocument2; const formNumber: integer; const fieldName, newValue: string) ;
var form : IHTMLFormElement;
field: IHTMLElement;
begin
form := WebFormGet(formNumber, WebBrowser1.Document AS IHTMLDocument2) ;
field := form.Item(fieldName,'') as IHTMLElement;
if field = nil then Exit;
if field.tagName = 'INPUT' then (field as IHTMLInputElement).value := newValue;
if field.tagName = 'SELECT' then (field as IHTMLSelectElement).value := newValue;
if field.tagName = 'TEXTAREA' then (field as IHTMLTextAreaElement).value := newValue;
end;
提交web表单是一种导航,因此在调用
tibAutentification后,您必须再次等待ReadyState
和Busy
属性。单击(这是web表单的提交按钮)。与第二次Navigate()
调用相同。此外,在等待浏览器准备就绪时,您需要泵送调用线程的消息队列,以便它能够正确地处理其状态更改
程序TMainForm.按钮10点击(发送方:TObject);
变量
文件:IHTMLDocument2;
文件3:IHTML文件3;
FileStream:TFileStream;
流适配器:IStream;
PersistStreamInit:IPersistStreamInit;
i、 a,b:整数;
主席先生:弦;
程序等待就绪;
开始
当WebBrowser1.ReadyState ReadyState_完成时
Application.ProcessMessages;
结束;
开始
WebBrowser1.导航('https://website/externallogin.aspx');
等待就绪;
doc:=WebBrowser1.作为IHTMLDocument2的文档;
doc3:=作为IHTMLDocument3的文件;
WebFormSetFieldValue(doc,0,'txtNume','user');
WebFormSetFieldValue(doc,0,'txtPwd','psswd');
doc3.GetElementByID('tibAutentification')。单击;
等待就绪;
WebBrowser1.导航('https://website/Pages/SearchTitle.aspx');
等待就绪;
doc:=WebBrowser1.作为IHTMLDocument2的文档;
doc3:=作为IHTMLDocument3的文件;
doc3.GetElementByID('chkTitleNo')。单击;
WebFormSetFieldValue(doc,0,'txtitleno','28972')//硝酸酯
doc3.GetElementByID('tibSearch')。单击;
WaitForReady;/?
doc:=WebBrowser1.作为IHTMLDocument2的文档;
doc3:=作为IHTMLDocument3的文件;
doc3.GetElementByID('fdgMain:_ctl3:imbView')。单击;
WaitForReady;/?
doc:=WebBrowser1.作为IHTMLDocument2的文档;
doc3:=作为IHTMLDocument3的文件;
doc3.GetElementByID('tibViewPDF')。单击;
结束;
程序TForm1.WebFormSetFieldValue(const文档:IHTMLDocument2;
const formNumber:integer;const fieldName,newValue:string);
变量
形式:IHTMLFormElement;
字段:IHTMlement;
开始
如果document=nil,则退出;
表单:=WebFormGet(表单编号、文档);
如果form=nil,则退出;
字段:=表单项(字段名“”),作为IHTMlement;
如果field=nil,则退出;
如果field.tagName='INPUT',则
(字段为IHTMLInputElement)。值:=newValue
否则,如果field.tagName='SELECT',则
(字段为IHTMLSelectElement)。值:=newValue
否则,如果field.tagName='TEXTAREA',则
(字段为IHTMLTextAreaElement)。值:=新值;
结束;
由于与手动泵送消息队列相关的重入问题,序列化此代码不是一个好主意,您应该使用浏览器的OnDocumentComplete
事件,让VCL为您处理消息,例如(可能需要一些调整):
程序TMainForm.按钮10点击(发送方:TObject);
开始
WebBrowser1.导航('https://website/externallogin.aspx');
WebBrowser1.标记:=1;
结束;
程序TMainForm.WebBrowser1文档完成(申请人:ToObject;
常量Disp:IDispatch;常量URL:OleVariant);
变量
文件:IHTMLDocument2;
文件3:IHTML文件3;
开始
案例WebBrowser1.的标签
1:开始
doc:=WebBrowser1.作为IHTMLDocument2的文档;
doc3:=作为IHTMLDocument3的文件;
WebFormSetFieldValue(doc,0,'txtNume','user');
WebFormSetFieldValue(doc,0,'txtPwd','psswd');
doc3.GetElementByID('tibAutentification')。单击;
WebBrowser1.标记:=2;
结束;
2:开始
WebBrowser1.导航('https://website/Pages/SearchTitle.aspx');
WebBrowser1.标记:=3;
结束;
3:开始
doc:=WebBrowser1.作为IHTMLDocument2的文档;
doc3:=作为IHTMLDocument3的文件;
doc3.GetElementByID('chkTitleNo')。单击;
WebFormSetFieldValue(doc,0,'txtitleno','28972')//硝酸酯
doc3.GetElementByID('tibSearch')。单击;
WebBrowser1.标记:=4;
结束;
4:开始
doc:=WebBrowser1.作为IHTMLDocument2的文档;
doc3:=作为IHTMLDocument3的文件;
doc3.GetElementByID('fdgMain:_ctl3:imbView')。单击;
WebBrowser1.标记:=5;
结束;
5:开始
doc:=WebBrowser1.作为IHTMLDocument2的文档;
doc3:=作为IHTMLDocument3的文件;
doc3.GetElementByID('tibViewPDF')。单击;
WebBrowser1.标记:=0;
结束;
结束;
结束;
提交web表单是一种导航,因此在调用tibAutentification后,您必须再次等待ReadyState
和Busy
属性。单击(这是web表单的提交按钮)。与第二次Navigate()
调用相同。此外,在等待浏览器准备就绪时,您需要泵送调用线程的消息队列,以便它能够正确地处理其状态更改
程序TMainForm.按钮10点击(发送方:TObject);
变量
文件:IHTMLDocument2;
文件3:IHTML文件3;
FileStream:TFileStream;
流适配器:IStream;
PersistStreamInit:IPersistStreamInit;
i、 a,b:整数;
主席先生:弦;
程序等待就绪;
开始
当WebBrowser1.ReadyState ReadyState_完成时
Application.ProcessMessages;
结束;
开始
WebBrowser1.导航('https://website/externallogin.aspx');
等待就绪;
doc:=WebBrowser1.作为IHTMLDocument2的文档;
doc3:=作为IHTMLDocument3的文件;
WebFormSetFieldValue(doc,0,'txtNume','user');
WebFormSetFieldValue(doc,0,'txtPwd','psswd');
doc3.GetElementByID('tibAutentification')。单击;
等待就绪;
WebBrowser1.导航('https://website