I have written some parts of a PhantomJS application. I am parsing on a website where I am writing username and password to a formular. After this I have to click on a link. Whereas I get this error:
TypeError: 'undefined' is not a function (evaluating 'myLink.click()')
phantomjs://webpage.evaluate():11
phantomjs://webpage.evaluate():22
phantomjs://webpage.evaluate():22
This is my PhantomJS code:
if(document.getElementById("m_Content_submitbtn2").getAttribute('data-role') == "button"){
var myLink = document.getElementById("m_Content_submitbtn2");
myLink.click();
}
And this is my link:
<div class='button'><a href="#" data-role="button" tabindex='0' onclick='WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("m$Content$submitbtn2", "", true, "", "", false, true)); return false;' id="m_Content_submitbtn2">Log ind</a></div>
You are attempting to use the click()
method on an <a>
element which is not supported in all browser by default. Instead try using something like this where instead of myLink.click();
you will have to do eventFire(myLink, 'click');
.
Or include jQuery and do something like:
var page = require('webpage').create();
page.open('http://www.sample.com', function() {
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
page.evaluate(function() {
$("button").click();
});
phantom.exit()
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With