doDoubleClick()
对我来说似乎不适用于 Chrome,我不知道为什么。在我写这篇文章时,我看到 ChomeDriver 正在执行操作。完成后,您将能够:
browser.moveToObject(someElement, x, y);
browser.actions().mouseDown().mouseUp().mouseDown().mouseUp().perform();
但是现在,当我使用 ChromeDriver 2.45 执行此操作时,我得到:
Error: unimplemented command: session/c4dae3dead96649fc7c26f75709257da/actions
因此,如果您不在遥远的未来,这对我有用:
function doubleClick(someElement, x, y) {
let attempt = 0;
let timeToDoubleClick;
do {
browser.moveToObject(someElement, x, y);
let startTime = Date.now();
browser.buttonPress(0).buttonPress(0);
timeToDoubleClick = Date.now() - startTime;
console.log("Time to double click: " + timeToDoubleClick);
if (timeToDoubleClick > 500) {
console.log("Waiting 10 seconds to allow the CPU to breath / check to see if a tab has opened...");
browser.pause(10000);
// In my case I'm expecting a new tab to open
if(browser.getTabIds().length > 1) {
// The tab opened!
timeToDoubleClick = 0;
}
}
} while(timeToDoubleClick > 500 && attempt++ <= 5);
if(attempt > 5) {
throw new Error("Could not manage to double click!");
}
}