• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Open firefox window and redirect to a url

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.lang.Runtime OR java.lang.Process
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You know it is dark times when the trees riot. I think this tiny ad is their leader:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic