Reputation: 79
Hello everybody I am a newbie on javascript and I am trying to learn Casper.js/Phantom.js, but today I encountered a problem. I am trying to login in https://angel.co/login?utm_source=top_nav_home site with auto filling. My code fills username and password correctly however my
casper.getElementsByName("commit").click();
doesnt work at all. So my program doesnt login to the account. When I inspect element I dont see any id tag, I see name so I use getElementByName.My code is like this below
phantom.casperPath = 'C:/casperjs';
phantom.injectJs(phantom.casperPath + '/bin/bootstrap.js');
var casper = require('casper').create({
pageSettings: {
loadImages: false,
loadPlugins: false,
userAgent: 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36'
}
});
//First step is to open angellist
casper.start().thenOpen("https://angel.co/login", function () {
console.log("angel website opened");
});
//lets fill username and pass login
casper.then(function () {
console.log("Login using username and password");
this.evaluate(function () {
document.getElementById("user_email").value = "myemail";
document.getElementById("user_password").value = "mypassword";
//casper.getElementsByName("commit").click();
//THIS ONE ABOVE DOESN'T WORK
});
});
after this I take a screenshot but I see that it doesnt click the login button. I tried to click it using xpath too but it didn'work. Thanks for your help.
Upvotes: 0
Views: 1680
Reputation: 79
I solved the problem by using fairly easy code
document.getElementsByName("commit")[0].click();
since getElementsByName returns an array we have to give an adress to is( like [0] or other values). I wont edit or remove this question, for the other newbies on javascript like me. Thanks to everybody
Upvotes: 1