Autor Beitrag
jackie05
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 357



BeitragVerfasst: Mi 08.10.08 22:58 
Hallo,
ich habe folgendes problem und zwar, lade ich eine Seite im WebBrowser1 und auf dieser Seite befinden sich 3 Buttons diese über JavaScript funktioneren:
ausblenden Quelltext
1:
<button type="button" onclick="submit()">senden</button><input id="action" type="hidden" name="action" value="send" />					


Jetzt möchte ich per Button1, den 2ten Button auf der Seite klicken lassen.
Ich habe das mal so versucht:
ausblenden Delphi-Quelltext
1:
Webbrowser1.OleObject.document.forms.item(2).submit();					


Der Code funktioniert nur einmal und fängt gleich eine exception ab und beim 2ten klick funktioniert der Code nicht mehr.

Wie könnte ich das ambesten lösen?

Vielen Dank schonmal für die Hilfe.

MfG
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 08.10.08 23:32 
Und du bist sicher, dass du da das richtige Item erwischst?
Welche Exception kommt denn?
jackie05 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 357



BeitragVerfasst: Mi 08.10.08 23:42 
Danke für die antwort.
Ich hab das mal gescreent:
Moderiert von user profile iconNarses: Bild als Anhang hochgeladen

Irgendwie geht das nicht, gibt es noch eine andere möglichkeit diesen Button anklicken zu lassen?

MfG
Einloggen, um Attachments anzusehen!
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 08.10.08 23:56 
Ja, lesen von Adresse 0, das bedeutet, dass du auf ein nicht existentes Objekt versuchst zuzugreifen. Du erwischst also offenbar nicht das richtige Objekt auf der Seite.
Ich bin mir nicht ganz sicher ob dir klar ist was "document.forms.item(2).submit()" bewirkt. Damit rufst du IMHO submit beim zweiten Formular auf, und nicht beim zweiten Button. Die Elemente innerhalb des Fomulars kannst du dann mit document.forms.item(2).elements.item(0) bekommen.
(Soweit ich mich erinnere, ist schon ne Weile her seit ich das letzte Mal mit TWebBrowser gearbeitet habe ;-).)
jackie05 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 357



BeitragVerfasst: Fr 10.10.08 01:40 
Das hat mir irgendwie nicht wirklich weitergeholfen.

Es müsste doch eine möglichkeit geben, den 2te Button klicken zu lassen :roll:

MfG
Logikmensch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 390

Win XP
Delphi 2007 Prof., XE2, XE5
BeitragVerfasst: Fr 10.10.08 06:09 
Ich finde, das hilft schon weiter....

ich würde jetzt erst mal ein

showmessage(inttostr(document.forms.items.count))

oder so probieren, um mir anzeigen zu lassen, wie viele Items überhaupt auf der Seite drauf sind.
Jaenicke meint ja im Prinzip auch, dass Deine Indizierung (2) nicht unbedingt das gewünschte Element anspricht.

_________________
Es gibt keine Probleme - nur Lösungen!
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 10.10.08 11:20 
Ja, und mehr kann man ja ohne die Website zu kennen nicht sagen. Wenn da nur ein Formular drauf ist, dann müsste es so ja klappen:
ausblenden Delphi-Quelltext
1:
WebBrowser1.OleObject.document.forms.item(0).submit()					
jackie05 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 357



BeitragVerfasst: Fr 10.10.08 23:28 
Danke, es befinden sich aber 3 Buttons auf der seite und der erste wird nur gedrückt, wenn ich diesen Code verwende, möchte aber das der 2te gedrückt wird.

MfG
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 10.10.08 23:33 
Ja, warum schaust du nicht einfach mal nach, ob da mehrere Formulare auf der Seite sind?
Raten würde ich, dass der zweite Button in einem zweiten Formular liegt und dieses also abgeschickt werden soll:
ausblenden Delphi-Quelltext
1:
WebBrowser1.OleObject.document.forms.item(1).submit()