简体   繁体   English

vb.net if webbrowser控件上的语句

[英]vb.net if statement on webbrowser control

Morning! 早上! (atleast in the US its morning). (至少在美国早上)。

I have an app with multiple buttons that load different sites using the webbrowser control. 我有一个带有多个按钮的应用程序,可使用webbrowser控件加载不同的网站。 I have the below code to auto login to an email website. 我有以下代码可以自动登录电子邮件网站。 However, if I browse to another site and then click the email signin button to execute the below code, it errors out. 但是,如果我浏览到另一个站点,然后单击“电子邮件登录”按钮以执行以下代码,则会出错。 It errors out because it already signed me in to the site the first time and now since the credentials are cached it logs me right in and bypasses the login page. 它之所以出错,是因为它已经是我第一次登录该站点,而现在由于缓存了凭据,它使我立即登录并绕过了登录页面。

How do I check if the login page doesn't exist, then exit sub. 如何检查登录页面是否不存在,然后退出sub。

WebBrowser1.Navigate(My.Settings.emailURL)
            WaitForPageLoad()
            WebBrowser1.Document.GetElementById("user").InnerText = My.Settings.emailUN
            WebBrowser1.Document.GetElementById("passwd").InnerText = My.Settings.emailPW
            'WebBrowser1.Document.GetElementById("remember_me").SetAttribute("checked", "false")
            WebBrowser1.Document.DomDocument.forms(0).submit()

I tried the below but it didn't work: 我尝试了以下操作,但没有成功:

If WebBrowser1.Navigate(My.Settings.emailURL) <> My.Settings.emailURL

Im assuming it didn't work because its a navigate command 我认为它不起作用是因为它的导航命令

Figured it out. 弄清楚了。 The web address is unique if you're signed in and displays a static web url, so I did a small if statement. 如果您登录后该网址是唯一的,并显示一个静态网址,所以我做了一个小的if语句。

If WebBrowser1.Url.AbsoluteUri.StartsWith(My.Settings.webmailURL)
Exit Sub
Else
Sign in......
end if

Hans thanks for the help, you got me thinking. 汉斯(Hans)感谢您的帮助,您让我开始思考。

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

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