javaseleniumwebdriverhtmlunit-driver

Cannot get Past the Login Page


I can't get pass the login page. I'm correctly grabbing the input elements, populating them, and submitting but I still end up on the original page. I'm unsure where the exact issue is and I've tried ".submit, .click, and emulated a javascript ENTER to submit the credentials.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    //Create driver, javascript enabled
    WebDriver driver = new HtmlUnitDriver(true);
    driver.get("https://epicmafia.com/home");
    //Get parent of login form
    WebElement parent = driver.findElement(By.id("login_form"));
    //Get both inputs of the login form
    //First is name
    //Second is password
    ArrayList<WebElement> children = new ArrayList<WebElement>();
    for(WebElement input : parent.findElements(By.cssSelector("input")))
        children.add(input);
    //Fill in name 
    children.get(0).sendKeys("USERNAME");
    //Fill in password 
    children.get(1).sendKeys("PASSWORD");
    //Wait for good measure
    driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
    //Submit credentials
    children.get(1).submit();
    //Double check inputs are desired values
    System.out.println("The username is: " + children.get(0).getAttribute("value"));
    System.out.println("The password is: " + children.get(1).getAttribute("value"));
    //Check if pass login page
    System.out.println("End URL is: " + driver.getCurrentUrl());
    driver.quit();      
} 

The login page is "https://epicmafia.com/home" while the next page upon successfully logging in would be "https://epicmafia.com/lobby".

edit: for reference: the third child element is the actual "Login" button that follows the first two(username and password).


Solution

  • After looking at replies and messing around a bit the answer wasn't an error in grabbing the elements, populating them or even submitting. The problem was coming from the timeout not working, where I'd presumably thought it was.

    I moved the driver to its own method kill switch so that the initial call has indefinite time to load before being manually killed off instead of automatically killed off as the code I originally posted.

    Now my problem of logging in is fixed and I have to look into why the timeout isn't working. Thank you all for the help.