如何在纯 phantomjs 上拖放?
How do drag&drop on pure phantomjs?
如何在没有 casperjs、selenium 等的情况下拖放纯 phantomjs?
我试过这段代码,但它不起作用
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();
});
我了解到它在 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();
});
如何在没有 casperjs、selenium 等的情况下拖放纯 phantomjs?
我试过这段代码,但它不起作用
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();
});
我了解到它在 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();
});