I'm trying to log into a site using Phantom JS so I can keep on top of my suppliers prices.
Username and password are being entered but the login button is not pressing.
If the login button is a <input> instead of <button>, .click() should work, however I cannot find a way to press the <button>.
The Log in form has no ID,NAME or ACTION to target a submit.
If anyone knows a solution I would be very grateful
thanks
Phantom JS
//username entered automatically on load
document.getElementById("password").value="1234";
document.getElementById('btn-login').click();
Login Form
<form onsubmit="return false;" method="post">
<fieldset class="customer-login">
<div class="form-group">
<label for="name">Email Address</label>
<input type="username" class="form-control" id="username" placeholder="Enter your email address">
</div>
<div class="form-group">
<label for="name">Password</label>
<input type="password" class="form-control" id="password" placeholder="Enter your password">
</div>
<button type="submit" id="btn-login" class="btn btn-primary btn-block">
Log In
</button>
<hr>
<button type="button" id="btn-signup" class="btn btn-default btn-block">
Sign Up
</button>
<button type="button" id="btn-reset" class="btn btn-default btn-block">
Forgotten your password?
</button>
</fieldset>
</form>
UPDATE
document.getElementsByClassName('btn btn-primary btn-block')[0].click();
works however as nothing returns and it redirects, it stops the program before it goes back to the home page logged in. Has anyone got a solution to get the program to wait (when it doesnt know its redirecting.)?
i tried
do { phantom.page.sendEvent('mousemove'); } while (page.loading);
When submitting the form, nothing was returned, so the program stopped. The program did not wait for the page to load as it took a few seconds for the redirect to begin.
telling it to move the mouse until the URL changes to the home page gave the browser as much time as it needed to change. then telling it to wait for the page to finish loading allowed the page to full load before the content was grabbed.
page.evaluate(function () {
document.getElementsByClassName('btn btn-primary btn-block')[0].click();
});
do { phantom.page.sendEvent('mousemove'); } while (page.evaluate(function()
{
return document.location != "https://www.bestwaywholesale.co.uk/";
}));
do { phantom.page.sendEvent('mousemove'); } while (page.loading);