javascript - calling click() function on html element in jasmine-phantomjs test -
this question has answer here:
- phantomjs; click element 11 answers
i run tests karma , phantomjs:
info [karma]: karma v0.12.32 server started @ http://localhost:9876/ info [launcher]: starting browser phantomjs info [phantomjs 1.9.8 (windows 7)]: connected on socket kvovdbbgtieuquv8aaaa wit
in test want click on paragraph (p) event-feedback:
// given var element = appendtobody("<p id='hello-p'>hello hello world!</p>"); element.addeventlistener('click', function(event) { console.log("1"); }); // when var p = document.getelementbyid("hello-p"); console.log(p); // log: <p id="hello-p">hello hello world!</p> console.log(p.id); // log: 'hello-p' p.click(); // calling click
i end having message:
typeerror: 'undefined' not function (evaluating 'p.click()')
q: why p undefined?
ok. bacause phantomjs based on webkit, have create/send event this:
var cle = document.createevent("mouseevent"); cle.initevent("click", true, true); var elem = document.getelementbyid('hello-p'); elem.dispatchevent(cle);
Comments
Post a Comment