简体   繁体   English

在VB.NET Webbrowser控件中检测Javascript html页面修改

[英]Detecting Javascript html page modification in VB.NET Webbrowser control

My VB.NET code is supposed to execute third party Javascript code in an attempt to fill in and submit a form.我的 VB.NET 代码应该执行第三方 Javascript 代码以尝试填写和提交表单。 This process consists of five steps, and I have been able to submit the form when all the steps are kept separate (ie behind 5 separate consecutive button clicks).这个过程由五个步骤组成,当所有步骤保持独立时(即在 5 个单独的连续按钮点击之后),我已经能够提交表单。 Now, what I'd like to have is one button to handle all the five steps.现在,我想要的是一个按钮来处理所有五个步骤。

The problem is that the form originally only appears after calling "webbrowser.Navigate" command, which apparently modifies the page's HTML code.问题是表单最初只在调用“webbrowser.Navigate”命令后才出现,这显然修改了页面的 HTML 代码。 I seem to be unable to detect when Javascript has finished loading the new HTML in order to fill and submit the form.我似乎无法检测到 Javascript 何时完成加载新 HTML 以填写和提交表单。 I have tried a timer control to wait for a certain HTML element ID to appear, but in vain.我尝试了一个计时器控件来等待某个 HTML 元素 ID 出现,但徒劳无功。

This question has been asked before in different forms, but at least I could not find much help from the earlier answers:这个问题之前已经以不同的形式提出过,但至少我无法从早期的答案中找到太多帮助:

InvalidCastException with WebBrowser.IsBusy or ReadyState (VB .NET) 带有 WebBrowser.IsBusy 或 ReadyState (VB .NET) 的 InvalidCastException

Detect when AJAX changes HTML in a DIV in WebBrowser 检测 AJAX 何时更改 WebBrowser 中 DIV 中的 HTML

http://www.techtalkz.com/vb-net/374234-vb-net-webbrowser-control-how-capture-javascript-events-statusbar-changed-mouseclick-etc.html http://www.techtalkz.com/vb-net/374234-vb-net-webbrowser-control-how-capture-javascript-events-statusbar-changed-mouseclick-etc.html

Please help me.请帮我。

Well, this is the way it normally works in the software industry: Only after you've explained the problem to others, are you in a position to sufficiently understand it - and solve it yourself.嗯,这就是它在软件行业的正常运作方式:只有在您向他人解释了问题之后,您才能充分理解它——并自己解决它。

The problem was that I had not been using System.Windows.Forms.Timer() but another (less suitable) timer class for tracking changes in the HTML code.问题是我没有使用 System.Windows.Forms.Timer() 而是使用另一个(不太合适的)计时器类来跟踪 HTML 代码中的更改。 This was the reason why Application.DoEvents() did not work.这就是 Application.DoEvents() 不起作用的原因。 With System.Windows.Forms.Timer() I was able to create a Timer.Tick event that keeps track of the phase of the form submittal (1-5 in my example) and attempts to execute the required Javascript commands in a Try-Catch construction.使用 System.Windows.Forms.Timer() 我能够创建一个 Timer.Tick 事件来跟踪表单提交的阶段(在我的示例中为 1-5)并尝试在 Try- 中执行所需的 Javascript 命令 -抓建设。 If an exception is caught, Application.DoEvents() is executed instead, and the timer ensures that the same commands are attempted to be executed shortly again.如果捕获到异常,则改为执行 Application.DoEvents(),并且计时器确保在短时间内再次尝试执行相同的命令。

This seems to work for me.这似乎对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM