Autor Beitrag
Bob Murphy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 91

XP, Ubuntu
Delphi 7 SE, Delphi 2007
BeitragVerfasst: Mi 25.11.09 07:00 
Moin,

zum klicken eines Links im TWebBrowser benutze ich diesen code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure WB_ClickLink(WB: TWebbrowser; const LinkText: string);
var
  HTMLDocument2: IHTMLDocument2;
  Element: IHTMLElement;
  I: Integer;
begin
  HTMLDocument2 := WB.Document as IHTMLDocument2;
  for I := 0 to HTMLDocument2.Links.Length - 1 do
  begin
    Element := HTMLDocument2.Links.Item(I, 0as IHTMLElement;
    if Element.GetAttribute('innerText'0) = LinkText then
    begin
      Element.Click;
      Break;
    end;
  end;
end;


Weis jemand wie ich diesen code zu umschreiben kann, damit er auch auf Frameseiten funktioniert?

LG
Bob Murphy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 91

XP, Ubuntu
Delphi 7 SE, Delphi 2007
BeitragVerfasst: So 29.11.09 23:47 
Ich möchte eigentlich nur einen TextLink auf einer bestimmten Frameseite klicken.
Hat denn niemand eine Idee?
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Mo 30.11.09 10:28 
probiers mal so
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
procedure WB_ClickLink(WB: TWebbrowser; const LinkText: string);
var
  HTMLDocument2: IHTMLDocument2;
  ole_index: OleVariant;
  Element: IHTMLElement;
  I, n: Integer;
  frame_dispatch: IDispatch;
  frame_win: IHTMLWindow2;
  frame_doc: IHTMLDocument2;
begin
  HTMLDocument2 := WB.Document as IHTMLDocument2;
  if HTMLDocument2.Frames.Length > 0 then
  begin
    for n := 0 to HTMLDocument2.Frames.Length - 1 do
    begin
      ole_index := n;
      frame_dispatch := HTMLDocument2.Frames.Item(ole_index);
      if frame_dispatch <> nil then
      begin
        frame_win := frame_dispatch as IHTMLWindow2;
        frame_doc := frame_win.document;
        for I := 0 to frame_doc.Links.Length - 1 do
        begin
          Element := frame_doc.Links.Item(I, 0as IHTMLElement;
          if Element.GetAttribute('innerText'0) = LinkText then
          begin
            Element.Click;
            Break;
          end;
        end;
      end;
    end;
  end
  else
  begin
    for I := 0 to HTMLDocument2.Links.Length - 1 do
    begin
      Element := HTMLDocument2.Links.Item(I, 0as IHTMLElement;
      if Element.GetAttribute('innerText'0) = LinkText then
      begin
        Element.Click;
        Break;
      end;
    end;
  end;
end;

_________________
mfg. Joel
Bob Murphy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 91

XP, Ubuntu
Delphi 7 SE, Delphi 2007
BeitragVerfasst: Mo 30.11.09 11:41 
Hey danke für deine Mühe.... allerdings bekomme ich in dieser Zeile: frame_doc := frame_win.document;
einen Zugriffsfehler "Zugriff verweigert".
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Mo 30.11.09 15:20 
kannst du eventuell mal die URL posten damit man das nachvollziehen kann?

_________________
mfg. Joel