浏览器自动化 - 将 javascript 附加到页面并等待任务完成
我有一个丑陋的数据输入任务需要自动化。问题是某些进程依赖于基于 Web 的 ajax 服务,而这些服务没有 API。
iMacros(或任何其他自动化工具)的问题是,每当宏将 javascript 注入页面(修改 ajax 回调并执行所有需要执行的操作)时,子脚本无法通知父脚本任务已准备就绪,并让它在一个线程中继续该过程。如果我使用 WAIT 指令,可靠性将为零,并且无法实现故障保护。
我尝试了所有我能想到的方法,包括 Chrome 扩展、降低 XSS 浏览器安全性,甚至通过 cURL 和 复制请求。 PHP。其中每一项都有其自身的局限性。
我对任何解决方案持开放态度:
- 可以等待页面完成加载(onload 事件)
- 可以修改该特定页面上的 javascript、与变量交互等
- 可以通知父调用者子任务已完成并正确触发事件
- 支持 flash
任何替代方案并提供帮助,非常感谢。
I have an ugly data entry task that needs automation. The problem is that some of the processes rely on web-based ajax services which have no API.
The problem with iMacros (or any other automation tool) is that whenever the macro injects javascript into a page (modifying ajax callbacks and doing all it needs to do), the child script has no way to notify the parent script that the task is ready, and let it continue the process in one single thread. If I use the WAIT instruction, reliability will be zero and there's no way to implement failsafes.
I tried anything I could think of, including Chrome Extensions, lowering XSS browser security and even replicating requests through cURL & PHP. Each one of these has its own limitations.
I'm open to any solution that:
- can wait for a page to finish loading (onload events)
- can modify the javascript on that particular page, interact with vars, etc.
- can notify the parent caller that sub-tasks are completed and fire proper events
- supports flash
Any alternative and help much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一篇以 Selenium 为中心的好文章,解释了等待 ajax 请求完成的不同方法:http://agilesoftwaretesting。 com/?p=111。
这比尝试修改现有的 JS 干净得多。以下任何一个都可以直接从 javascript 调用,因此只要您的自动化框架支持调用 javascript(Selenium/webdriver 就支持),那么您只需调用这些函数,具体取决于您的网站使用的 ajax 库:
jQuery: “jQuery .active”
原型:“Ajax.activeRequestCount”
Dojo:“dojo.io.XMLHTTPTransport.inFlight.length”
只需检查以确保该值为 0,然后继续。
Here is a good article that is Selenium centric explaining different ways to wait for ajax requests to finish: http://agilesoftwaretesting.com/?p=111.
This is much cleaner than trying to modify the existing JS. Any of the following can be called from javascript directly, so as long as your automation framework supports calling javascript (which Selenium/webdriver does) then you just call these functions, depending on which ajax libraries your web site are using:
jQuery: “jQuery.active”
Prototype: “Ajax.activeRequestCount”
Dojo: “dojo.io.XMLHTTPTransport.inFlight.length”
Just check to make sure the value is 0 and then continue.