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.
|
1 answer
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);' + '})();'; |
TWebBrowser. Yes, and analyze the headlines, too, does not hurt, understand, at what level there is the possibility of working with Ajax. - SoftRNavigate('javascript:...');doesn't it work? - Sh4dow