Puppeteer - 从框架集中的第 5 级深度子页面调用外部 JS 函数 [英] Puppeteer - invoke external JS function from a 5th level deep child page in frameset

查看:47
本文介绍了Puppeteer - 从框架集中的第 5 级深度子页面调用外部 JS 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在一个建立在 apache Struts 框架上的已有 20 年历史的电子商务网站上实现 puppeteer 自动化.我无法复制整个 struts 操作 servlet,但是我模拟了 HTML 页面,一旦人们登录并选择商店,这些页面就会在框架中加载 14 个不同的页面.目标是从第 5 个深度子框架页面中加载的 14 个页面之一中单击 Create New Shopping Basket.该链接调用外部 javascript 函数,但木偶操作者返回此错误:

I am trying to achieve puppeteer automation on a 20 year old e-commerce site which is built on apache Struts framework. I cannot replicate the entire struts action servlets, however I have simulated the HTML pages that get loads 14 different pages in frames once the person logs in and selects the Shop. The goal is to click the Create New Shopping Basket from one of the 14 pages that are loaded in the 5th deep child frame page. That link calls an external javascript function, but the puppeteer returns this error:

Error: Evaluation failed: ReferenceError: create_order is not defined
    at __puppeteer_evaluation_script__:1:8
    at ExecutionContext._evaluateInternal (<path>/headless-chrome/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221:19)
    at async ExecutionContext.evaluate (<path>/headless-chrome/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:110:16)
    at async Promise.all (index 1)
    at async <path>/headless-chrome/simulation/index.js:40:5

这是所有 html 文件、外部 javascript 文件和 puppeteer js 文件的链接.https://github.com/samgajjar/headless-chrome

Here is the link to all html files, the external javascript file and the puppeteer js file. https://github.com/samgajjar/headless-chrome

解压所有 zip 文件,这里是如何手动导航

Extract all zip file and here is how to navigate manually

  • 打开 Login.html
  • 可以输入任何用户名/密码并点击登录按钮
  • 这将显示商店列表
  • 选择商店 ISA_2120_EN
  • 这将打开加载 14 个文件的框架集从这里开始,脚本应该点击 Create New Shopping Basket 调用一个 js 函数 - create_order(),它在 make_new_doc.js 文件中

puppeteer index.js 确实执行了商店的登录和选择,但在创建购物篮时出现上述错误

The puppeteer index.js does execute the login and selection of the shop but error on creating the basket with above error

谢谢!!

推荐答案

我尝试使用框架并取得了一些进展.它加载框架集,但是有一些与内存分配相关的东西.如果我加载页面 frameset.html 然后它加载框架集的整个树,headless = true 或 false 如下:

I tried working with frames and made some progress. It loads the frameset, however there is something related to memory allocation. If I load the page frameset.html then it loads the entire tree of the frameset, either headless = true or false as follows:

  blank1
  isaTop
    header
    organizer_nav
    organizer_content
    closer_organizer
    work_history
      documents
      banner
      spacer
      form_input
      closer_history
      _history
    footer
  blank2

但是,如果我从登录导航 ->选择商店->带有 headless = false 的框架集,那么最低级别的框架没有任何实例,我得到以下列表:

However if I navigate from login -> selectshop -> frameset with headless = false then the lowest level frames does not have any instance and I get the following list:

  blank1
  isaTop
    header
    organizer_nav
    organizer_content
    closer_organizer
    work_history






    footer
  blank2

但是,如果我通过导航但 headless = true 则结果如下:

However if I go thru the navigation but with headless = true then the result is as follows:

  blank1
  isaTop
    header
    organizer_nav
    organizer_content
    closer_organizer
    work_history
      documents
      banner




    footer
  blank2

这篇关于Puppeteer - 从框架集中的第 5 级深度子页面调用外部 JS 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆