如何检查 Web 浏览器控件中托管的页面是否已呈现?
大家好!我再次来这里寻求你的帮助。我在 Wpf 应用程序中有一个 Web 浏览器控件。在主窗口的事件 Load 中,我设置了控件的源:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
webBrowser1.Source = new Uri(ConnectionString);
webBrowser1.Navigate(ConnectionString);
}
此时我必须使用我的 Windows Live ID 登录。为此,我查找输入控件,以便用我的用户名和通行证填充它们,然后单击提交按钮以调用事件 Click():
HTMLDocument mdoc = (HTMLDocument)webBrowser1.Document;
IHTMLElement usern = mdoc.getElementById("i0116");
IHTMLElement dom = mdoc.getElementById("i0118");
IHTMLElement btl = mdoc.getElementById("idSIButton9");
if (usern != null && dom != null && btl != null)
{
// pass authentication
usern.setAttribute("value", UserName);
dom.setAttribute("value", password);
btl.click();
IsRendered=true;
}
这是问题!。如果页面尚未呈现,则过程 getElementById 返回 Null!!。
有什么方法可以知道页面何时完全呈现? 提前致谢!
Hy People!. I'm here again asking for your help. I have a web browser control in a Wpf App. Into the event Load of the mainwindows I set up the control's source:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
webBrowser1.Source = new Uri(ConnectionString);
webBrowser1.Navigate(ConnectionString);
}
I'm redirected to the following url: https://login.live.com/login.srf?wa=wsignin1.0&wtrealm=urn%3acrm%3adynamics.com&wctx=rm%3d1%26id%3de513a320-df72-4de8-bce8-b1f918dc4eff%26ru%3dhttps%253a%252f%252fwebfortis38.crm.dynamics.com%252fdefault.aspx&wct=2011-09-06T14%3a49%3a38Z
At this point I must Sign in with my Windows Live Id. To do that I look for the Input controls in order to fill them up with my username and my Pass, and then the button submit in order to calls the event Click():
HTMLDocument mdoc = (HTMLDocument)webBrowser1.Document;
IHTMLElement usern = mdoc.getElementById("i0116");
IHTMLElement dom = mdoc.getElementById("i0118");
IHTMLElement btl = mdoc.getElementById("idSIButton9");
if (usern != null && dom != null && btl != null)
{
// pass authentication
usern.setAttribute("value", UserName);
dom.setAttribute("value", password);
btl.click();
IsRendered=true;
}
HERE IS THE PROBLEM!. If the page is not already rendered, the procedure getElementById returns Null!!.
Is there any way to know when the page is completely rendered?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 webBrowser1 的 Navigated 事件。
You can use Navigated event of webBrowser1.
嘿,a可以解决这个问题。我所做的就是创建一个新线程。在这个新线程中,我将代码插入到 DO-WHILE 循环中,并将 thread.abort() 插入到 IF 循环中。感谢您的帮助
Hy, a could solve the problem. What I've done is to create a new thread. Into this new thread I've inserted my code into a DO-WHILE loop and with a thread.abort() into the IF loop. Thanks for the help