Welcome Guest Search | Active Topics | Sign In | Register

call js script after the page loaded completely Options
Nifeng
Posted: Sunday, October 21, 2018 5:23:48 AM
Rank: Newbie
Groups: Member

Joined: 10/21/2018
Posts: 5
Hi,

I am trying to auto login to the target site and call some js script like below :

Load the target url

m_CurPage.WebView.LoadUrlAndWait("https://target");

fill in the login information

m_CurPage.WebView.QueueScriptCall("document.getElementById('hd_account').setAttribute(\"value\",\"name\");");
m_CurPage.WebView.QueueScriptCall("document.getElementById('hd_passwd').setAttribute(\"value\",\"password\");");

call the js function to pre-login

//m_CurPage.WebView.QueueScriptCall("Pre-login();");
m_CurPage.WebView.QueueScriptCall("document.getElementsByName('Submit')[0].click();");

accept the policy to login

m_CurPage.WebView.QueueScriptCall("loginAgree();");

at this moment , I loged in
but the js function 'loginAgree();' called the '$.reload();' to reload the index.jsp . I must wait for the index.jsp loaded completely to do the next job . If I call the js script at this moment , the element would not load yet

I want to call the js script function below after login

//m_CurPage.WebView.EvalScript("document.getElementById('cboxOverlay').remove(); ");
//m_CurPage.WebView.EvalScript("document.getElementById('colorbox').remove(); ");

the question is , how can I know when the page is loaded completely ?
eo_support
Posted: Monday, October 22, 2018 8:11:05 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,258
Hi,

There are different stages of "page loaded completely". The first stage involves of loading the main document and is the equivalent of body.load event. This is what LoadUrlAndWait satisfies. By the time LoadUrlAndWait returns, the main document has already been completely loaded/parsed.

However this does not mean your page is already fully functioning. Particularly your page can have additional JavaScript code that is still running. As a simple example, your main page could contains JavaScript code that plays a fancy animation before finally displaying the login user name/password box to the user. So while the page is technically "loaded completely" as long as the initial page (which contains the JavaScript code that does the animation and dynamically display the login UI) is loaded, the page is not ready to interact with user until the fancy animation is done playing and the login UI is finally displayed. Another common scenario is the initial page only contains some dynamic loading script which then calls back to the server through AJAX to load additional information. In this case the page is not fully functioning until these additional AJAX calls are completed.

These scenarios have to do with your page and there is no generic method to capture when the page is really ready. As such you will have to look into your page to see if you can identify what mechanism you can use to determine whether the page is ready. We only provide the basic means for you to do so. There are a couple of things that you may find useful:

1. WebView.JSInitCode. This property allows you to inject your own JavaScript code into the page to be loaded;
2. WebView.EvalScript. This allows you to run any script code in the page. The difference between this one and #1 is the script code in #1 is run BEFORE any other JavaScript code in the page;
3. JavaScript extension:

https://www.essentialobjects.com/doc/webbrowser/advanced/jsext.aspx

This feature allows you to call back into .NET from JavaScript (the opposite direction of EvalScript);

You can use a combination of these features to implement whatever mechanism that will work for your particular page.

Hope this helps. Please feel free to let us know if you have any more questions.

Thanks!

Nifeng
Posted: Monday, October 22, 2018 3:32:26 PM
Rank: Newbie
Groups: Member

Joined: 10/21/2018
Posts: 5

Thank you for your very clear answer. I understand that strictly speaking, this is not a technical question of EO. Your answer has helped me found the way to solve my problem. thank you very much.
I will try the method you told me to find a solution.
When I have other problems in the future, I may need your further help. Thank you
eo_support
Posted: Monday, October 22, 2018 4:29:14 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,258
You are very welcome. Please feel free to let us know if you have any more questions.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.