单击和鼠标悬浮
和表单交互
1 .选择,取消
2 .单选按钮
3 .上传文件
使用键盘
使用鼠标
1 .mouseMoveTo()
2 .竟然没有模拟鼠标滚轮的行为
3 .只能函数注入了
截图的用处
1 .生成pdf
2 .进行前后ui的对比
3 .生成原型稿
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({
headless:false
});
const page = await browser.newPage();
await page.goto('https://www.jd.com');
await page.setViewport({
width:1200,
height:800
})
await autoScroll(page)
await page.screenshot({
path: 'hua1.png',
fullPage:true
});
// await browser.close();
})();
async function autoScroll(page){
await page.evaluate(async () => {
await new Promise((resolve, reject) => {
var totalHeight = 0;
var distance = 1000;
var timer = setInterval(() => {
var scrollHeight = document.body.scrollHeight;
window.scrollBy(0, distance);
totalHeight += distance;
if(totalHeight >= scrollHeight){
clearInterval(timer);
resolve();
}
}, 1000);
});
});
}