Directly submitting the form
You're probably unable to pass the username/password in the URL due to the fact that the server-side implementation expects the Content-Type to be application/x-www-form-urlencoded, multipart/form-data or application/json.
Instead of using https://mywebsite.com/login?username=myusername&password=mypassword you probably need to use something like:
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: mywebsite.com
Connection: close
User-Agent: Some User Agent
Content-Length: xxx
username=myusername&password=mypassword
The User-Agent header is often necessary to not get blocked on the server side (403 Forbidden).
One way of actually checking this is to use Firebug or Chrome Developer tools to check how the login data will be sent to the server and mimic that behavior.
Using Selenium with HTML form
Using Selenium you can also fill in a form.
If it opens in a new window/tab/popup, you can select the right window. Assuming driver is the WebDriver you're using.
ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
for (String tab : tabs) {
driver.switchTo().window(tab);
// Either get it by its url
if (driver.getCurrentUrl().equals("https://mywebsite.com/my-login") {
// Do the login
}
// Detect based on HTML on the page
if (driver.findElement(By.cssSelector(".my-form-class #my-form-id")).size() != 0) {
// Do the login
}
}
When the login screen get loaded by JavaScript you can wait for the element to become available in the DOM. Again assuming driver is the WebDriver you're using.
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".my-form-class #my-form-id")));
Now you can actually fill in the form:
driver.findElement(By.cssSelector(".my-form-class .username")).sendKeys("your-actual-username");
driver.findElement(By.cssSelector(".my-form-class .password")).sendKeys("your-actual-password");
driver.findElement(By.cssSelector(".my-form-class .submit-button")).click();
Write code to verify a successful login.
Interacting with Flash
If the login is an actual Flash object, you're probably forced to use the Java Robot class. Thereby performing a sequence of steps:
mouseMove to the location of the username/email field
mousePress to click the form field
keyPress to fill in you username
Repeat for password and submit button. Check if the login actually was successful.
Additionally you can use the conductor framework, which can make testing with Selenium easier.