如果没有casperjs,selenium等,如何拖放纯粹的幻影?
我尝试了这段代码,但它不起作用
var page = new WebPage();
page.open("http://html5demos.com/drag", function()
{
var coordOne = page.evaluate(function() { return document.getElementById("one").getBoundingClientRect(); });
var coordBin = page.evaluate(function() { return document.getElementById("bin").getBoundingClientRect(); });
console.log(coordOne.left + "x" + coordOne.top);
console.log(coordBin.left + "x" + coordBin.top);
page.sendEvent("mousemove", coordOne.left, coordOne.top);
page.render('screenshot1.png');
page.sendEvent("mousedown", coordOne.left, coordOne.top);
page.sendEvent("mousemove", coordBin.left, coordBin.top);
page.sendEvent("mouseup", coordBin.left, coordBin.top);
page.render('screenshot2.png');
phantom.exit();
});
答案 0 :(得分:0)
我读到它在html5中不起作用。在普通代码中它起作用:
var page = new WebPage();
page.open("http://www.snook.ca/technical/mootoolsdragdrop/", function()
{
var coordOne = page.evaluate(function() { return document.getElementById("dragger").getBoundingClientRect(); });
var coordBin = page.evaluate(function() { return document.getElementsByClassName("item")[0].getBoundingClientRect(); });
console.log(coordOne.left + "x" + coordOne.top);
console.log(coordBin.left + "x" + coordBin.top);
page.sendEvent("mousedown", coordOne.left+1, coordOne.top+1);
page.sendEvent("mousemove", coordBin.left+1, coordBin.top+1);
page.sendEvent("mouseup", coordBin.left+1, coordBin.top+1);
page.render('screenshot.png');
phantom.exit();
});