Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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: 74085
332
  • 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: 74085
332
  • 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
 
yeah, but ... what would PIE do? Especially concerning this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic