每当网站显示来自jQuery事件的以下消息时,我都会尝试检索。最初这个HTML inst显示在HTML中。
<div id="toast-container" class="toast-top-right"><div class="toast toast-error" aria-live="assertive" style="display: block;"><div class="toast-message">Check email & password.</div></div></div>
我的假设是, webBrowser1.DocumentText.Contains 仅从内容的初始加载开始。
所以我想也许某种计时器会每5秒钟工作一次,看看代码是否已经改变 - 但我甚至认为这是正确的,因为它正在检查已经重复加载的代码?
private void timer2_Tick(object sender, EventArgs e)
{
// Checks for any errors on sign in page
if (webBrowser1.DocumentText.Contains("toast toast-error"))
{
// Toast Notifications
var signinErrorNotification = new Notification("Error", "Please check your email and password are correct.", 50, FormAnimator.AnimationMethod.Fade, FormAnimator.AnimationDirection.Left);
signinErrorNotification.Show();
}
}
如何获取受任何jQuery影响的最新代码。
P.S。我的c#级别是初学者。
答案 0 :(得分:0)
Document属性应该为您提供所需的内容。
请注意,DocumentText的文档说
获取或设置WebBrowser中显示的页面的HTML内容 控制。
对于他们说的文件
获取一个HtmlDocument,表示当前在WebBrowser控件中显示的Web页面。
对我而言,DocumentText就像起始文档而Document是当前的DOM。另请参阅https://docs.microsoft.com/en-us/dotnet/framework/winforms/controls/how-to-access-the-managed-html-document-object-model