1

I want to learn how to:

Step1: open URL – for example Gmail

Step 2: insert user and password and press sign-in.

How can I inset user and password and press the sign-in button?

Do I need/must use selenium?

This code is only for open the browser(step 1)

import java.io.IOException;

public class Website
{

public void openWebsite() //throws IOException
{
    try 
    {
        @SuppressWarnings("unused")
Process p = Runtime.getRuntime().exec("cmd /c start http://accounts.google.com/ServiceLogin ");
    }
    catch (IOException e1)
    {
        System.out.println(e1);
    }
}
}    
2
  • yes, you need to use something as Selenium Commented Apr 8, 2013 at 14:40
  • Not necessarily. Use a tool like firebug to find the form and the name of its input fields for username/password. Then make a request to the action url with the input fields of the form. You wouldn't be using the your browser for this, just java. Commented Apr 8, 2013 at 14:43

1 Answer 1

1

First you need to open the URL. Right now you are actually not opening the URL. You are asking the Windows operating system "What would you do with http://accounts.google.com/ServiceLogin?"

Because it is windows, it will make a guess, which sort of follows this line of logic:

 it sort of looks like a URL, so I'll fire up explorer and 
 ask explorer to do something with it.

Which means that your code is now a few programs away from being able to get the data, and none of the intermediate programs will (because they're not built to do so), transmit the need for input into your program.

What you need to do is to avoid asking other programs to open the URL, it's just too problematic. First, they might get it wrong, second they'll never know how to ask you the input. To open a URL directly:

import java.net.URL;

... somewhere in the code ...

  URL url = new URL("http://accounts.google.com/ServiceLogin");
  InputStream in = url.openStream();

do some googling on various java.net.URL tutorials, and you will soon find the right combination of techniques needed to handle your particular credential challenge. Here's one resource, but it seems you need to do a bit of homework before what they say will make sense to you. If you stumble, at least you'll have a better, more specific question to ask the next time around (and don't forget to post your source code).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.