views:

346

answers:

3

is it possible to login to sites like facebook,gmail using iwebbrowser2?

in the code below what can i add so that it can login to gmail(with ie8 as browser) using the username and password i put in a variable?

MyBrowser := CreateOleObject('InternetExplorer.Application') as IWebBrowser2; 
MyBrowser.Navigate('http://mysite.com'..........???);

note : i am a newbie.

sorry for my english:)

and thanks in advance

A: 

You can use javascript 'injection' to control your site. By 'injection' I mean that once your gmail page is loaded you then construct a url in the form

javascript:var Email = document.getElementById('Email');Email.value='User.Name';

javascript:var Password = document.getElementById('Passwd');Password.value='YourPassword';

javascript:var SignIn = document.getElementById('signIn');SignIn.click();

or you can throw it all onto one URL

javascript:var Email = document.getElementById('Email');Email.value='User.Name';var Password = document.getElementById('Passwd');Password.value='YourPassword';var SignIn = document.getElementById('signIn');SignIn.click();

Your code would then look something like:

MyBrowser := CreateOleObject('InternetExplorer.Application') as IWebBrowser2; 
MyBrowser.Navigate('http://www.gmail.com');

myUserName := 'User.Name';
myPassword := 'password';
loginURL:='javascript:var Email = document.getElementById(''Email'');Email.value=''' + myUserName + ''';var Password = document.getElementById(''Passwd'');Password.value=''' + myPassword + ''';var SignIn = document.getElementById(''signIn'');SignIn.click();';

MyBrowser.Navigate(loginURL);
blissapp
1.what am i supposed to put in the uses clause?i mean which unit? my delphi ide is underlining createoleobject and other things(with red color) which means something has to be put in the uses clause(i put 'activex' and 'ComObj' but ide is still underlining so it has to be some thing else) and i am missing it,2. also do i have to write mybroweser := iwebbrowser2 in the var section?if yes then why not just 'MyBrowser := CreateOleObject('InternetExplorer.Application') as IWebBrowser2;' wont that automatically declare mybrowser as iwebbrowser2 variable? thanks in advance
Omair Iqbal
Ask another question, I just answered the "how to remote control" question, I'm not close enough to Delphi to answer this for you.
blissapp
A: 

Try using TWebBrowser instead. TWebBrowser encapsulates the IWebBrowser2 interface.

Here's a link to an example showing how to do a POST with TWebBrowser.

If you use the Indy HTTP and SSL components, you'll have more flexibility.

Marcus Adams
A: 

Send data to url

MyBrowser.Navigate('http://mysite.com', Flags, EmptyParam, PostData, Headers); 

and you need to fill the PostData and Headers as in the link below http://forums.devshed.com/showpost.php?p=2408145&postcount=2

I already answer this question here: http://stackoverflow.com/questions/2842452/open-default-browser-with-a-post-in-delphi/2842831#2842831

TridenT