0

I've found lot of streams addressing my problem but I was not able to successfully apply the "answers".

When I'm using the webBrowser to access a URL based on HTTPS, I have the two well knowed "Security Alert" winodws which appear.

Security Alert Step 1

Security Alert Step 2

So for me the only solution would be to 'SendKeys.Send("{ENTER}")' for the first step and for the second one use 'SendKeys.Send("{LEFT}")' + 'SendKeys.Send("{ENTER}")'. But It's not working...

Here is my code:

webBrowser1.Navigate("https://...")
SendKeys.Send("{ENTER}")
SendKeys.Send("{LEFT}")
SendKeys.Send("{ENTER}")

I've also try :

System.Windows.Forms.SendKeys.SendWait("{ENTER}")

or

SendKeys.SendWait("{Enter}")

Finally, I've also found this solution for C# but I don't know how to translate it in VB.net:

int iHandle = NativeWin32.FindWindow(null, "Security Alert");
NativeWin32.SetForegroundWindow(iHandle);
System.Windows.Forms.SendKeys.Send("{ENTER}");

I'm really lost so if someone could help me it will be very appreciated !!

Thanks.

noseratio
  • 59,932
  • 34
  • 208
  • 486
SkorPPio
  • 43
  • 3
  • 8
  • Are you sure that the webbrowser has the focus in your first code? Try webBrowser1.Navigate("https://...") then webBrowser1.Focus() and, after that, SendKeys. This is NOT the ideal solution, but should work. Note that Navigate and Focus/Sendkeys shouldn't be one after the other; you have to access anything you are navigating to from the DocumentCompleted event. – varocarbas Nov 27 '13 at 14:11
  • I've update my code as requested with wb.Focus() followed by SendKeys.Send("{ENTER}") but it's still not working. It's just like before... – SkorPPio Nov 27 '13 at 14:52
  • Are you executing Focus ans SendKeys from the DocumentCompleted event? The second code you are proposing does basically the same. Can you please share the link to replicate your conditions? – varocarbas Nov 27 '13 at 14:59
  • I cannot share the link because it refers to a private server in my lab... I'm not executing them in DocumentCompleted. But inside this sub I've added a MsgBox followed by SendKeys.Send("{ENTER}") but again the send key seems to not work. – SkorPPio Nov 27 '13 at 15:10
  • Why you are executing anything outside documentCompleted? When you type webBrowser1.Navigate("https://...") it takes a while to navigate to this site, load the whole page and show this message, for example; if you write any command right below .Navigate it would be executed BEFORE the page is loaded. Thus you using SendKeys when the prompt with the buttons you are intending to press is not even there yet. Please do a test with all the code after Navigate in the DocumentCompleted method. – varocarbas Nov 27 '13 at 15:13
  • PS: the second code you suggested does exactly the same than your first one in an unnecessarily more intrincate way (it gets the handle of the message window, brings it to the front and uses SendKeys identically). A more adequate alternative to use this second approach would be: using the handle of the message window (iHandle) to affect the window directly and click on the button you want "from inside"; SendKeys basically does everything "from outside". Also both codes would fail in case of not being called from the DocumentCompleted method. – varocarbas Nov 27 '13 at 15:17
  • Actually, when the code execute .Navigate(htps://...) it display the Security Alert message before continue to load the page. As you already know, everything that you put in "DocumentCompleted" will not be executed until the end of the load process. Which is not what we want to do as we need click on "Yes" during the load. – SkorPPio Nov 27 '13 at 15:22
  • This is one of the reasons why I have requested you to provided replicable conditions (the "it does not work like this in my computer"-kind of claims are very time consuming, tiring and unhelpful to both the helper and the person being helped). What I can warrant you is that some event will be triggered and that this message will not happen immediately after .Navigate. If documentCompleted is not triggered (not sure; because this message avoids the page to load and thus might trigger it), test other similar events, find out which one is triggered and put your code inside it. – varocarbas Nov 27 '13 at 15:27

0 Answers0