Node.js   发布时间:2022-04-24  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何使用node.js控制浏览器(ala Selenium)?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我听说过 soda,但似乎需要你注册并且分钟数有限(免费acct / 200分钟).

有没有人知道是否有一些替代方法来控制浏览器,或者更具体地是在网页上调用JS?

解决方法

https://github.com/LearnBoost/soda/raw/master/examples/google.js

/**
 * Module dependencies.
 */

var soda = require('../'),assert = require('assert');

var browser = soda.createClient({
    host: 'localhost',port: 4444,url: 'http://www.google.com',browser: 'firefox'
});

browser.on('command',function(cmd,args){
  console.log(' \x1b[33m%s\x1b[0m: %s',cmd,args.join(','));
});

browser
  .chain
  .session()
  .open('/')
  .type('q','Hello World')
  .clickAndWait('btnG')
  .gettitle(function(titlE){
    assert.ok(~title.indexOf('Hello World'),'title did not include the query');
  })
  .clickAndWait('link=Advanced search')
  .waitForPageToLoad(2000)
  .assertText('css=#gen-query','Hello World')
  .assertAttribute('as_q@value','Hello World')
  .TESTComplete()
  .end(function(err){
    if (err) throw err;
    console.log('done');
  });

大佬总结

以上是大佬教程为你收集整理的如何使用node.js控制浏览器(ala Selenium)?全部内容,希望文章能够帮你解决如何使用node.js控制浏览器(ala Selenium)?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。