使用WebBrowser自动填写AngularJS表单 [英] Using WebBrowser to automate filling in an AngularJS form
本文介绍了使用WebBrowser自动填写AngularJS表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用WebBrowser在使用AngularJS的网站上自动填充文本框.
I am using WebBrowser to automate filling in a textbox, on a website that uses AngularJS.
这是他们网站上的HTML
This is the HTML on their website
<input name="email" type="email" placeholder="Email address" ng-model="login.email" autofocus="" class="ng-pristine ng-valid ng-empty ng-valid-email ng-touched" aria-invalid="false">
这是我的C#代码
webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("email")[0].SetAttribute("value", _login);
这将填充输入框,但我认为它不会更新Angular模型.
因此,您不能提交表单,因为该网站(即Angular)认为它仍然为空.
That populates the input box, but I don't think it updates the Angular model.
Hence you can't submit the form because that website (ie. Angular) thinks it is still empty.
如何从WebBrowser控件中触发ng-model更新?
How do you trigger the ng-model update from my WebBrowser control?
推荐答案
这是更新ng-model所需的脚本
This is the script needed to update ng-model
angular.element($("input[name='email']")).triggerHandler('change')
您可以像这样从WebBrowser执行它
and you can execute it from WebBrowser like this
wb.Document.InvokeScript("eval", new[] { "angular.element($('input[name=email]')).val('your@email').triggerHandler('change')" });
这篇关于使用WebBrowser自动填写AngularJS表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文