Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Open firefox window and redirect to a url

 
Teena Mariam
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello,

Is there any possibility to open firefox(version independent) in Linux using Java (Without javascript)?
The program should open firefox with the url : http://www.gmail.com and it should automatically populate the user id and password and should log in. We can provide the user id and password in a text file.

Thanks in advace,
Teena
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
campbell@queeg:~$ firefox --h
Usage: /usr/lib/firefox-3.0.13/firefox [ options ... ] [URL]
where options include:

X11 options
--display=DISPLAY X display to use
--sync Make X calls synchronous
--no-xshm Don't use X shared memory extension
--xim-preedit=STYLE
--xim-status=STYLE
--g-fatal-warnings Make all warnings fatal

Mozilla options
-height <value> Set height of startup window to <value>.
-h or -help Print this message.
-width <value> Set width of startup window to <value>.
-v or -version Print Firefox version.
-P <profile> Start with <profile>.
-ProfileManager Start with ProfileManager.
-no-remote Open new instance, not a new window in running instance.
-UILocale <locale> Start with <locale> resources as UI Locale.
-safe-mode Disables extensions and themes for this session.
-jsconsole Open the Error console.
campbell@queeg:~$
campbell@queeg:~$ firefox http://www.javaranch.com
campbell@queeg:~$
. . . and a JavaRanch tab opened. I don't know whether it is possible to provide a user name too. Beware: if you put your password in an unencrypted file, it is at risk of hacking.

You would need to start a Process with Runtime.exec(). Before doing that, be sure to read Michael Daconta's article "when Runtime.exec() won't".
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:You would need to start a Process with Runtime.exec(). Before doing that, be sure to read Michael Daconta's article "when Runtime.exec() won't".

Thanks Campbell, I didn't know that !
 
Adam Michalik
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the site you are trying to open supports parameters via HTML GET, you can build the URL with them (eg. http://www.gmail.com?user=somename&password=somepassword). However, I don't thing that GMail supports such a thing (especially sending the password in the URL). But the user can switch on a "remember me" option in GMail so that whenever the site is opened, the user logged in automatically. This is done by Firefox and cookies, so no effort on Java side (but the user will have to log in manually for the first time and enable the "remember me" function).
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar Rohankar wrote:Thanks Campbell, I didn't know that !
You're welcome Lots of people think it is easy to use Runtime.exec() but the Daconta article shows it is quite difficult.
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Teena:

You might consider looking into using Selenium. Selenium is made for this kind of thing (web testing), and has a Java API (along with a number of other languages). It is also widely used. You can check it out here.

John.
 
sarath gopal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Teena,

did you try Java Desktop api..you can use it to launch browser without any difficulty
use this link for intro
Using Desktop API
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic