程序自動點擊 DIV標籤 [webbrowser] |
答題得分者是:washare
|
devhp
一般會員 發表:6 回覆:10 積分:3 註冊:2007-06-12 發送簡訊給我 |
webbrowser 開啟下麵的頁面后 如何自動點擊或者後台模擬鼠標點擊 指定DIV標籤
實際問題是這樣子的呢。我想用程序去操作GOOGLE的DOC,請從下麵的鏈接進入看下 https://www.google.com/accounts/ServiceLoginBoxAuth?Email=wo.de.doc2008@gmail.com&Passwd=de111111&continue=https://docs.google.com 比如自動點擊 菜單項 [Hide] [Delete] 以及所有類似的DIV標籤
[code delphi] for k := 0 to web[i].OleObject.Document.all.tags('Div').Length - 1 do begin startag := web[i].oleobject.document.all.tags('Div').item(k).innertext; if ansicontainsstr(startag,seedstr.Text) then begin web[i].oleobject.document.all.tags('DIV').item(k).click; memo1.Lines.Add('已點擊!' startag inttostr(k)); end; end; [/code] 答案出來了!在這里非常感謝朋友 [washare],下麵是具體操作第i個DIV標籤代碼 [code delphi] Wb.OleObject.document.parentWindow.document.all.tags('DIV').item(i).FireEvent('on_mouse_down',EmptyParam);//請把on_mouse_down的底線"_"delete掉即可 Wb.OleObject.document.parentWindow.document.all.tags('DIV').item(i).FireEvent('on_mouse_up',EmptyParam) ;//請把on_mouse_up底線"_"拿掉即可 [/code]
------
dfs 編輯記錄
devhp 重新編輯於 2009-03-19 14:38:06, 註解 無‧
devhp 重新編輯於 2009-03-19 14:40:12, 註解 無‧ devhp 重新編輯於 2009-03-19 14:46:30, 註解 無‧ devhp 重新編輯於 2009-03-19 14:48:38, 註解 無‧ taishyang 重新編輯於 2009-03-19 14:49:41, 註解 移除[求救]字樣‧ devhp 重新編輯於 2009-03-25 14:59:28, 註解 無‧ devhp 重新編輯於 2009-03-25 15:40:33, 註解 無‧ devhp 重新編輯於 2009-03-25 15:42:19, 註解 無‧ devhp 重新編輯於 2009-03-25 15:50:30, 註解 無‧ devhp 重新編輯於 2009-03-25 15:57:02, 註解 論壇有BUG,會執行JS‧ yckuo 重新編輯於 2009-03-25 16:17:01, 註解 套用程式碼區塊‧ yckuo 重新編輯於 2009-03-25 16:19:29, 註解 無‧ devhp 重新編輯於 2009-03-26 00:07:09, 註解 無‧ devhp 重新編輯於 2009-03-26 00:08:58, 註解 無‧ devhp 重新編輯於 2009-03-28 17:35:10, 註解 無‧ |
washare
初階會員 發表:14 回覆:36 積分:35 註冊:2006-10-17 發送簡訊給我 |
你的never online本身如果是一個超連結的話,可以試試下面的程式碼
這是以前用過的source剪出來的,沒特別為你 試過 如果點擊的東西本身是一個連結的話,應該透過這種方式都能達成 Link(doc,'never online').click; function Link(ADoc: IHTMLDocument2; AUrl: WideString): HTMLLinkElement; //取得指定文字它所指向的超連結 var oLinks: IHTMLElementCollection; oLink: HTMLLinkElement; i: Integer; s:widestring; begin if ADoc=nil then exit; Result:= nil; try oLinks:= ADoc.links as IHTMLElementCollection; for i:= 0 to oLinks.length-1 do begin oLink:= oLinks.item(i,0) as HTMLLinkElement; s:=oLink.href; //if SameText(oLink.href,AUrl) then if SameText(oLink.innerText,AUrl) then begin Result:= oLink; exit; end; end; except end; end; |
devhp
一般會員 發表:6 回覆:10 積分:3 註冊:2007-06-12 發送簡訊給我 |
===================引 用 washare 文 章=================== 你的never online本身如果是一個超連結的話,可以試試下面的程式碼 這是以前用過的source剪出來的,沒特別為你 試過 如果點擊的東西本身是一個連結的話,應該透過這種方式都能達成 首先謝謝您的回復! 這種方法我知道,它本身不是鏈接,所以上面的方法是抓不到它的 用下麵的方式可以抓到,可是沒有反應,不明白是沒有click呢還是不用使用click; [code delphi] for k := 0 to web[i].OleObject.Document.all.tags('Div').Length - 1 do begin startag := web[i].oleobject.document.all.tags('Div').item(k).innertext; if ansicontainsstr(startag,seedstr.Text) then begin web[i].oleobject.document.all.tags('DIV').item(k).click; memo1.Lines.Add('已點擊!' startag inttostr(k)); end; end; [/code]
------
dfs |
washare
初階會員 發表:14 回覆:36 積分:35 註冊:2006-10-17 發送簡訊給我 |
|
devhp
一般會員 發表:6 回覆:10 積分:3 註冊:2007-06-12 發送簡訊給我 |
朋友您好:
論壇好像有些BUG,代碼不管怎麼貼出來都會執行里面的JS代碼所以我發到別的地方請幫偶看看 http://hi.baidu.com/szba/blog/item/5c1cd6030c5e9ce409fa93c2.html 謝謝 我的郵箱:wuma5201#hotmail.com###
------
dfs
編輯記錄
devhp 重新編輯於 2009-03-25 16:01:28, 註解 無‧
|
washare
初階會員 發表:14 回覆:36 積分:35 註冊:2006-10-17 發送簡訊給我 |
我想我應該沒有看眼花,從你的html看來never-online,並沒有任何事件跟它關連,你的alert();是寫在doc.on_mouse_down上,如果你只是要去觸發alert();,那應該直接去觸發doc_on_mouse_down,跟click never-online這個div好像沒什麼關連,不太懂你的問題。不然就是你的_on_mouse_down應該寫到div裏面,這樣你去觸發div的click應該就會有反應了,是不是你把事件寫錯地方了
|
devhp
一般會員 發表:6 回覆:10 積分:3 註冊:2007-06-12 發送簡訊給我 |
真是非常感謝您的細心,
實際問題是這樣子的呢。我想用程序去操作GOOGLE的DOC,請從下麵的鏈接進入看下 https://www.google.com/accounts/ServiceLoginBoxAuth?Email=wo.de.doc2008@gmail.com&Passwd=de111111&continue=https://docs.google.com 比如自動點擊 菜單項[File]>document
------
dfs |
washare
初階會員 發表:14 回覆:36 積分:35 註冊:2006-10-17 發送簡訊給我 |
我覺得你好像把問題想的太複雜了,如果你是要點擊菜點的某個功能,如你給的連結點進去後,的new\document<---這個會進入文件編輯模式
那你只需要如下的程式碼就能完成 寫這行就像你去click菜單一樣 HccWebBrowser1.Navigate('https://docs.google.com/DocAction?action=newdoc&source=doclist&hl=en'); 所以你只需要知道每個菜單執行的是那個url就行了 這個答案是你要的嗎? //------------------------------ [code delphi] unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, OleCtrls, SHDocVw, HccWeb, StdCtrls; type TForm1 = class(TForm) HccWebBrowser1: THccWebBrowser; Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin HccWebBrowser1.Navigate('https://www.google.com/accounts/ServiceLoginBoxAuth?Email=wo.de.doc2008@gmail.com&Passwd=de111111&continue=https://docs.google.com'); end; procedure TForm1.Button2Click(Sender: TObject); begin HccWebBrowser1.Navigate('https://docs.google.com/DocAction?action=newdoc&source=doclist&hl=en'); end; end. [/code]
編輯記錄
washare 重新編輯於 2009-03-25 23:30:00, 註解 無‧
|
devhp
一般會員 發表:6 回覆:10 積分:3 註冊:2007-06-12 發送簡訊給我 |
|
washare
初階會員 發表:14 回覆:36 積分:35 註冊:2006-10-17 發送簡訊給我 |
//下面是測試時的source,實際使用時,直接用GetElementByID取得delete的div就行了 procedure THccWebBrowser.ClickDiv(Doc2: IHTMLDocument2); var divs: IHTMLElementCollection; e: DispHTMLDivElement; i: Integer; ws,cn,id:widestring; r:OleVariant; s:string; DIVDisp,tempDisp:IDispatch; begin if Doc2=nil then exit; try DIVDisp:= doc2.all.tags('DIV') ; if DIVDisp=nil then exit; divs:=DIVDisp as IHTMLElementCollection ; if divs=nil then exit; for i:= 0 to divs.length-1 do begin e:= divs.item(i,0) as DispHTMLDivElement; cn:=e._className; id:=e.id; if id=':z' then //delete的id begin e.FireEvent('onmousedown',EmptyParam) ; e.FireEvent('onmouseup',EmptyParam) ; end; end; except end; end; |
devhp
一般會員 發表:6 回覆:10 積分:3 註冊:2007-06-12 發送簡訊給我 |
|
washare
初階會員 發表:14 回覆:36 積分:35 註冊:2006-10-17 發送簡訊給我 |
天呀,source又被網站自動改了喔!
我把source code 傳到你的hotmail,你收看看 [code delphi] procedure THccWebBrowser.ClickDiv(Doc2: IHTMLDocument2); var divs: IHTMLElementCollection; e: DispHTMLDivElement; i: Integer; ws,cn,id:widestring; r:OleVariant; s:string; DIVDisp,tempDisp:IDispatch; begin if Doc2=nil then exit; try DIVDisp:= doc2.all.tags('DIV') ; if DIVDisp=nil then exit; divs:=DIVDisp as IHTMLElementCollection ; if divs=nil then exit; for i:= 0 to divs.length-1 do begin e:= divs.item(i,0) as DispHTMLDivElement; cn:=e._className; id:=e.id; if id=':z' then begin e.FireEvent('on_mouse_down',EmptyParam) ;//請把on_mouse_down的底線"_"delete掉即可 e.FireEvent('on_mouse_up',EmptyParam) ;//請把on_mouse_up底線"_"拿掉即可 end; end; except end; end; [/code] |
devhp
一般會員 發表:6 回覆:10 積分:3 註冊:2007-06-12 發送簡訊給我 |
首先感謝您的技術,再次感謝您的熱心!,讓我又學會一種方法,雖然還是不太清楚 [FireEvent] 的其它具體用法,
下麵我簡化了一下具體操作第 i 個DIV標籤的方法,以便其他朋友們參考! [code delphi] [/code] Wb.OleObject.document.parentWindow.document.all.tags('DIV').item(i).FireEvent('onmousedown',EmptyParam); Wb.OleObject.document.parentWindow.document.all.tags('DIV').item(i).FireEvent('onmouseup',EmptyParam);
------
dfs |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |