Results 1 to 16 of 16
  1. #1
    bssunil46 is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default How to open a mozilla browser from java swing applicaiton

    Hi All,

    I am developing a Java Swing GUI for linux which should open an firefox instance (upon selecting a client and url from Jlist box) populate username and password (which is obtained from a database) and submit it.

    Please advise me on how to achieve this. Is there an mozilla api that I can use to achieve this?

    Thanks and Regards,
    Sunil.

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    The Desktop class can do some of the work for you but what is the purpose of this requirement?

  3. #3
    bssunil46 is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default Re: How to open a mozilla browser from java swing applicaiton

    I have tried using Desktop class, I am able to invoke mozilla browser but cannot fill the form i.e., login details and submit it.

    Application requirment is to invoke a mozilla with selected uri, auto fill login details (username and password) and submit the form, to get the next page.

    For eg: If user selects gmail from java applicaiton, then it should open an instance of mozilla with www.gmail.com, auto fill username and password and submit it. The user can then navigate to different pages like inbox, sent mail etc.

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Why can't the users fill in their credentials themselves?

  5. #5
    bssunil46 is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default How to open a mozilla browser from java swing applicaiton

    The requirment of the application is to get the details (url, username and password) from the database, invoke the mozilla browser, auto fill login details and submit the page so the user logs in and the next page is available for him to navigate.

    For eg: when user presses gmail from a java applicaiton, a mozilla browser should open with www.gmail.com, fill username and password and submit it. The user will then be able to see the next page which has inbox, sent mails etc and he should be able to navigate further.

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

  7. #7
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    364
    Rep Power
    5

    Default

    Very interesting topic
    i decided to try mu luck :)

    Here's some code I have written quickly
    to get you starting fast
    please don't hesitate to make any kind of comment on it


    Java Code:
    /**
    import java.awt.AWTException;
    import java.awt.Robot;
    import java.awt.event.KeyEvent;
    import java.io.IOException;
    
    
     * Gmail login Robot - auto fill login details and submit the page
     * @author dren
     * 
     * README:
     * 
     * BEFORE YOU RUN IT: fix path to firefox on local computer
     * 
     * TIPS: Beware of: 
     * What window is active at the moment,
     * How much time it takes before system loads firefox,
     * Are there any browser pop-ups like "Do you want ... to remember your password", that you have to click
     * 
     *
     */
    public class Robot_Gmail {
    
    	static int keyInputUsername[] = {
    			KeyEvent.VK_H,
    			KeyEvent.VK_E,
    			KeyEvent.VK_L,
    			KeyEvent.VK_L,
    			KeyEvent.VK_O,
    			
    			KeyEvent.VK_TAB,
    			
    			KeyEvent.VK_W,
    			KeyEvent.VK_O,
    			KeyEvent.VK_R,
    			KeyEvent.VK_L,
    			KeyEvent.VK_D,
    			
    			KeyEvent.VK_TAB,
    			KeyEvent.VK_TAB,
    			KeyEvent.VK_ENTER,
    			
    	};//end keyInput array
    	
    	
    	public static void main(String[] args) throws IOException, AWTException {
    
    		
    		String gmail = "https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=zpwhtygjntrz&scc=1&ltmpl=default&ltmplcache=2";
    		
    		/*start firefox in separate process*/
    		
    		/*it has to become ACTIVE window with focus on 'Username' field, with cursor blinking inside of it*/
    		Runtime.getRuntime().exec("\"C:\\Program Files\\Mozilla Firefox\\firefox.exe\" \"" + gmail + "\"");
    		
    		/*Robot used to enter username and password and clik in 'Sign in' button */
    		Robot robot = new Robot();
    		
    		/*to make enough time to firefox to open and focus on username field; 
    		 * without this line, writing will be immidiately initited in current window not firefox - during testing in Eclipse editor*/
    		robot.delay(5000);
    		
    		
    		/*enter username, 
    		 * tab, 
    		 * enter passeord, 
    		 * tab, tab,
    		 *  ENTER - for clicking on 'Sign in'*/
    		for (int oneLetter : keyInputUsername){
    			robot.keyPress(oneLetter);
    			robot.delay(500);
    		}
    		
    		
    		
    	}//
    }///

  8. #8
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Just use the Desktop class like I said before in the thread to open the page using the default browser.

  9. #9
    Vinay is offline Member
    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0

    Default

    Hi FON,
    can you please let me know how to pass the contents of textfile on a webpage..... with the help of above pgm......
    I need to pass some input which I have stored in a txt file on my hard drive. so how can I pass it......

  10. #10
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    364
    Rep Power
    5

    Default

    Quote Originally Posted by Vinay View Post
    Hi FON,
    can you please let me know how to pass the contents of textfile on a webpage..... with the help of above pgm......
    I need to pass some input which I have stored in a txt file on my hard drive. so how can I pass it......

    Why do you need robot for this ?

  11. #11
    Vinay is offline Member
    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0

    Default About the code

    Yes I need to develop robot for this......... can you pls help me!!!!

  12. #12
    Vinay is offline Member
    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0

    Default

    Is there any solution for the above question......

  13. #13
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Quote Originally Posted by Vinay View Post
    Is there any solution for the above question......
    Hopefully, not. There are enough spambots in existence without adding one more in Java.

    db

  14. #14
    Vinay is offline Member
    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0

    Default Darryl.Burke

    I am not creating any spam bots..........
    i am working on two websites which are owned by us legally....... just need to create some automation task for few pages.......

    anywaz thanks for help from ur forum

  15. #15
    ak88 is offline Member
    Join Date
    Jul 2009
    Posts
    17
    Rep Power
    0

    Default

    Have u found the solution for this problem
    I also need to open gmail.com and fille the form and sign in using java. But for me the username and password are fixed.
    I tried but not able to achieve it.
    Can anyone help me out with the code .......

  16. #16
    Vinay is offline Member
    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0

    Default

    Don't try with java..... try using vb.net..... its much easier......
    try using web browser concept....

    Thanks

Similar Threads

  1. Open and closing tabbed web browser using java
    By rijeshmenon in forum Advanced Java
    Replies: 0
    Last Post: 12-14-2009, 09:44 AM
  2. Replies: 3
    Last Post: 11-09-2009, 12:12 AM
  3. Open and close web browser
    By ali_sakar in forum New To Java
    Replies: 2
    Last Post: 11-03-2009, 12:28 PM
  4. Mozilla using the same session ID for different browser
    By ajith_raj in forum Advanced Java
    Replies: 1
    Last Post: 04-23-2009, 12:31 PM
  5. Re-open browser
    By Tokajac in forum Java Servlet
    Replies: 2
    Last Post: 10-13-2008, 01:31 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •