0

I am new in C# language and I have been trying to automate a website using .NET based webbrowser for ONLY personal use in Visual Studio 2015.

I have done document parsing, used Timer, used DocumentCompleted event properly to wait for the webpage to load completely and then parse the content, tried to make async events to behave like sync events (in order to load HTML content generated by clicking a link in a fully loaded webpage), etc to go through the phases in webpage automation: login -> get trains between stations -> click the Book now link -> go to the next page and fill in the passenger details.

Everything works fine but I am now stuck at the last phase, i.e., "go to the next page and fill in the passenger details" has a captcha image that must be resolved to go to the payment page. Don't get me wrong because I am not trying to get this captcha resolved automatically. The problem here is that I do not see the captch image which turned to be loaded only when this javascript call is invoked $(document).ready.

I thought my project has some buggy code which is stopping to load the captcha and therefore, I created a very basic new project, only added below code and navigated through different phases myself to see if the captcha really loads but unfortunately it would not load.

namespace TestWebBrowser
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            webBrowser1.Navigate("https://www.irctc.co.in/eticketing/loginHome.jsf");
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {

        }
    }
}

Please see below. The highlighted part is where I am expecting a captcha.

enter image description here

I must tell you that I am not a web designer and therefore I only understand very basic of how websites work.

I went through several questions on this forum and nothing helped me.

Internet explorer is also using .NET browser from behind but while using IE, I can see the captcha is getting loaded. So, why is this javascript call $(document).ready is not getting invoked in .NET browser. Please see below:

enter image description here

I have later tried to use CefSharp in a fresh new project and I can see the captcha is getting loaded in its chromium based webbrowser. But I have done so much coding with .NET based webbrowser already and therefore I want to stick to the latter at this moment in order to get this resolved.

Is this happening because .NET webbrowser is using some very old IE version configurations?

Please help me to understand.

UPDATE 1: Adding the javascript

<script type="text/javascript">
        $(document).ready(function(){
            var isJsBlocked=0;
            if (typeof(nlpLoadCaptchaAsync) == 'function'){                     
                nlpLoadCaptchaAsync();
            }else{
                isJsBlocked=1;
            }
            setTimeout(function(){
                var isNLPCaptcha = document.getElementById('nlpIdentifier');                        
                if(isNLPCaptcha == null || isNLPCaptcha=='' ) {
                    var nlptrack = new Image();
                    nlptrack.src="http://irctclive.nlpcaptcha.in/temp_redirect_count/irctc_timeout.php?ref=f2c5d744485b0b4251461454db791111&isJsBlocked="+isJsBlocked+"&dynamicParameter="+Date.now();
                    nlpCaptchaTimeOut(true);

                }

            }, 5000 ); 

        });  
        </script>
Rohit
  • 604
  • 1
  • 10
  • 25
  • Is there a url that can be used for testing? There is most likely a javascript error not compatible with IE and the the url https://www.irctc.co.in/eticketing/loginHome.jsf in your question is not the same as what I see in my browser. – Alexander Higgins Jul 02 '17 at 20:11
  • @AlexanderHiggins: After login, the URL changes. That is why you do not see the same URL. Unfortunately, you have to use `https://www.irctc.co.in/eticketing/loginHome.jsf`and login with correct credentials to move to the problematic page. I showed the image also from IE browser. Its getting loaded there but not getting loaded in the .NET webbrowser. – Rohit Jul 02 '17 at 20:16
  • @AlexanderHiggins: this is the URL `https://www.irctc.co.in/eticketing/trainbetweenstns.jsf` where the captcha is not getting loaded in the .NET browser. After login from the first URL, you cannot use this URL manually to again in the same tab, new tab, etc see the page because it would again land to the login page. – Rohit Jul 02 '17 at 20:20
  • 1
    @Rohit `$(document).ready` is using the `jQuery` library which is only supporting `Internet Explorer: 9+` https://jquery.com/browser-support/. You may want to take a look at that question: https://stackoverflow.com/q/17922308/5111904 – Matthias Herrmann Jul 02 '17 at 20:22
  • Since I can't get to it, make sure you are not suppressing script errors in your webbrowser control. – Alexander Higgins Jul 02 '17 at 20:22
  • @MatthiasHerrmann: I'll give it a try and get back. Thanks :) – Rohit Jul 02 '17 at 20:23
  • @AlexanderHiggins: I am not suppressing any error but yes, I see javascript error popup every time. – Rohit Jul 02 '17 at 20:24
  • @MatthiasHerrmann: Thanks. This solved the problem :) – Rohit Jul 03 '17 at 17:49

1 Answers1

1

The answer shared here: Use latest version of Internet Explorer in the webbrowser control solved my issue.

I basically had to change the version of IE version used by my webbrowser control.

Thanks to Matthias herrmann

Rohit
  • 604
  • 1
  • 10
  • 25