在使用greasemonkey过程中,对angularJS框架的WEB 进行自动表单提交动作。


发现JQuery的对inputd的val()赋值操作会使原有的angularJS的绑定验证操作失效。


虽然我在赋值的同时使用的jQuery的change 和trigger方法都没有效果。


查找stackoverflow上看到一个人的情况与我类似,并且下面的解决办法我经过测试也是没有问题的,完美的解决我的问题。


参照歪果仁的一个解决办法:

  1. Set the value.
  2. Send a change event. For Greasemonkey/Tampermonkey scripts you must be mindful of the sandboxes and jQuery conflicts for this part.
    Using ajQuery.change(), or.trigger(), from a userscript that is not injected, seldom works. Send a proper change event; see below.
  3. Since you@required jQuery (good), but used@grant none(bad), your script was causing the page to crash and you would see various errors in the console.
  4. The script has a race condition and was often firing before the inputs were ready. Waiting forwindow.loadseems to be enough, but you may have to step up to something likewaitForKeyElements()if you should see more timing problems.
  5. There may be additional timing issues with the$('#SignupButton').click ();If so, that's outside the scope of this question.
  6. DO NOT USE THIS KNOWLEDGE TO VIOLATE ANY WEBSITE'S TERMS OF SERVICE. (If applicable)

With that, the script becomes:

// ==UserScript== // @name Roblox Account Create // @match https://www.roblox.com/ // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js // @grant GM_addStyle // ==/UserScript== var _adj = [ 'Cool', 'Masked', 'Bloody', 'Lame' ]; var _animals = [ 'Hamster', 'Moose', 'Lama', 'Duck' ]; var _months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]; var _username = _adj[ parseInt( Math.random( ) * _adj.length ) ], _pass = Math.random( ).toString( 36 ).substring( 2, 10 ); _username += _animals[ parseInt( Math.random( ) * _animals.length ) ]; _username += parseInt( Math.random( ) * 1000 ); var _dt_month = _months[ Math.floor( Math.random( ) * ( 12 ) + 0 ) ]; var _dt_day = Math.floor( Math.random( ) * ( 28 ) + 1 ); var _dt_year = Math.floor( Math.random( ) * ( 2005 - 1916 + 1 ) + 1916 ); window.addEventListener ("load", function load () { setControl ('Username', _username ); setControl ('Password', _pass ); setControl ('PasswordConfirm', _pass ); setControl ('MonthDropdown', _dt_month ); setControl ('DayDropdown', _dt_day ); setControl ('YearDropdown', _dt_year ); $( '#FemaleButton' ).click( ); $( '#SignupButton' ).click( ); } ); function setControl (elemID, value) { var zInput = $( '#' + elemID ); zInput.val( value ); var changeEvent = document.createEvent ("HTMLEvents"); changeEvent.initEvent ("change", true, true); zInput[0].dispatchEvent (changeEvent); }


Note that we use a valid@grantvalue, other thannone. That's crucial to avoid conflicts with the page's javascript.


参考地址:http://stackoverflow.com/questions/34360739/automate-form-submission-on-an-angularjs-website-using-tampermonkey



更多相关文章

  1. js之DOM操作(访问父节点parentNode)
  2. javascript对iframe的互操作浅析
  3. Python 内置函数及excel操作
  4. 【项目实战】自监控-09-DataFrame索引操作(上篇)
  5. 求助:Python是否可以用一行代码来同时给变量赋值并打印变量的值
  6. Python文件操作大全,随机删除文件夹内的任意文件
  7. 使用Python操作MongoDB
  8. Cloud Pub / Sub Demo:403未授权用户执行此操作。当试图推送通知
  9. Python 文件的基本操作

随机推荐

  1. C#与.net框架之间的关系是什么?C#程序的开
  2. .NET Core中如何使用Entity Framework操
  3. c#是什么?有什么用?
  4. 浅谈.NET Core开发日志中Edge.js是什么?如
  5. 如何用C语言计算矩形的周长和面积?(附代码)
  6. C#执行原理深入解析(图文)
  7. C#如何冒泡排序?冒泡排序程序的编写
  8. C#如何使用 OleDbConnection 连接读取Exc
  9. C#如何连接数据库?OleDbConnection与SqlCo
  10. VS2015新建一个完整的c++工程详细步骤