Faced a problem: I can not programmatically "click" on a "button" in Webbrowser or a link in the form of a button, if its href property contains a script. Links of the form: a href="/index.php pressed perfectly ( ...Item(i).Click; ). But these do not want: a href="javascript: quick_login()" , i.e. something On the page it happens, but there is no result. Attempts to emulate onclick , onmouseup , onmousedown do not help.

  • The content of the quick_login () function can I see? - Palmervan 1:31 pm
  • This function is shown for example, on the target page the function is different. There is a web application on Ajax, in it an embedded frame with the search form, these links are the results that the form displays if there are several of them; when the result is one, there are no problems. When clicked, replaces the contents of the nested frame with information for the found object. ) - sunhunter
  • In order to do it in JavaScript, so that students do not write clicker. Analyze what the page sends to the server and by what method, and do the same sending, and do not use it in TWebBrowser . Yes, and analyze the headlines, too, does not hurt, understand, at what level there is the possibility of working with Ajax. - SoftR
  • And Navigate('javascript:...'); doesn't it work? - Sh4dow
  • Thank you all for the advice, in general, the output found a non-standard ... even somewhat perverted. Actually because of what did not work Item (i) .Click; -> due to the fact that the link does not have an onclick property. And to set this property to me does not interfere. Those. 1. find the element 2. read the href property 3. create the new onclick property of the element (we take the value from href) 4. click ... - sunhunter

1 answer 1

Actually, we look, we sort. It works, checked) Learn JS and look for the link somehow, at least by text (innerHTML), at least by sequence number, whatever you want)

This code goes to Hashcode, looks for the "Questions" button and pokes it. CMD in this form is only for readability + take into account the maximum length of the URL, like 1024. If you need more, run in parts (first window.myFunc = function() {alert("lol");} , then window.myFunc(); )

Yes, I tried on Delphi7, if that.

 procedure TForm1.FormCreate(Sender: TObject); begin WebBrowser1.Navigate('http://hashcode.ru/'); end; procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant); var cmd: string; begin if (URL='http://hashcode.ru/') then begin cmd := 'javascript:' + '(function(){' + 'var l=document.getElementsByTagName("a");' + 'for(var i=0;i<l.length;i++)' + 'if (l[i].innerHTML=="Вопросы")' + 'l[i].click();' + '})();'; WebBrowser1.Navigate(cmd); end; end; 

CMD for authorization of VKontakte ( as if I hint as correct - it is not necessary to do so, but it is necessary to be able to )

  cmd := 'javascript:' + '(function(){' + 'document.getElementById("quick_email").value="my@email.com";' + 'document.getElementById("quick_pass").value="myVeryLongPassword";' + 'setTimeout(function(){document.getElementById("quick_login_form").submit();}, 10);' + '})();';