Files
site-portfolio/shclick.mjs
T

23 lines
1.2 KiB
JavaScript

import puppeteer from 'puppeteer';
const b = await puppeteer.launch({ args:['--no-sandbox','--disable-setuid-sandbox','--use-gl=angle','--enable-unsafe-swiftshader'] });
const p = await b.newPage();
await p.setViewport({width:1280,height:1000});
await p.goto('http://10.200.201.3:4175/_lab/neu-card.html',{waitUntil:'load',timeout:60000});
await new Promise(r=>setTimeout(r,1200));
// подпишемся на клик по ссылке внутри страницы
await p.evaluate(()=>{
window.__clicked=false;
document.querySelector('#sec-shader a.contact-card').addEventListener('click', ()=>{ window.__clicked=true; }, true);
});
const link = await p.$('#sec-shader a.contact-card');
const box = await link.boundingBox();
await p.mouse.click(box.x+box.width/2, box.y+box.height/2);
await new Promise(r=>setTimeout(r,300));
const clicked = await p.evaluate(()=>window.__clicked);
// hover тоже
await p.mouse.move(box.x+box.width/2, box.y+box.height/2);
await new Promise(r=>setTimeout(r,400));
const hover = await p.evaluate(()=>getComputedStyle(document.querySelector('#sec-shader a.contact-card')).transform);
console.log(JSON.stringify({clicked, hover},null,1));
await b.close();