boundingBox();

>获取元素的位置信息

mouse.move()

  1. # 核心api
  2. var position = await ele.boundingBox(); //获取元素的位置信息
  1. const puppeteer = require("puppeteer");
  2. const url = "https://account.aliyun.com/register/register.html";
  3. async function show () {
  4. const browser = await puppeteer.launch({
  5. headless:false,
  6. defaultViewport: null, //可视区域最大化
  7. });
  8. const page = await browser.newPage();
  9. await page.goto(url)
  10. /* 切换iframe */
  11. const frame = await page.$("#alibaba-register-box");
  12. const html = await frame.contentFrame();
  13. /*进度条 */
  14. var span = await html.$(".nc-lang-cnt")
  15. var span_info = await span.boundingBox();
  16. await page.mouse.move(span_info.x,span_info.y);
  17. await page.mouse.down();
  18. for(var i=0;i<span_info.width;i++){
  19. await page.mouse.move(span_info.x+i,span_info.y)
  20. }
  21. await page.mouse.up();
  22. }
  23. show()