0

I am trying to login to a website and navigating to my dashboard page which essentially requires login element followed by the page to be opened. The Page i was trying to open will be active only after login to the first page.

My Code -

    var page = require('webpage').create();
phantom.cookiesEnabled = true;
page.onConsoleMessage = function(msg) {
    console.log(msg);
};
page.open("https://login-page", function(status) {
    if (status === "success") {
        page.evaluate(function() {
            console.log('Step 1 - Login JIRA');
        document.getElementById("login-form-username").value = "user";
        document.getElementById("login-form-password").value = "password";
        document.getElementById("login-form-submit").click();

        });
        window.setTimeout(function() {
            console.log('Step 2 - Save login page');
           page.render("page.png");

           page.open("https://page-after-login-to-take-screenshot", function(status) {

                window.setTimeout(function() {
                    console.log('Step 3 - Save current page');

                   page.render("profil.png");

                   phantom.exit();
                }, 5000);
            });
        }, 5000);
    }
});

After running my code i am not able to see any output and also i didnt get any screenshots saved

C:\user\phantomjs-2.1.1-windows\phantomjs-2.1.1-windows\bin> .\phantomjs.exe I:\my_code\try2.js
***Nothing Happened****

After giving the console output to check what happening in the each step i got the below output -

DEPRECATED JS - Cookie has been deprecated since 5.8.0 and will be removed in a future release. Use cookie instead.   
 No stack trace of the deprecated usage is available in your current browser.
Project create didn't get a user META tag, or it had no content.  Bailing out
DEPRECATED JS - Dropdown constructor has been deprecated and will be removed in a future release. Use Dropdown2 instead.   
 No stack trace of the deprecated usage is available in your current browser.
Downloading resources:

Step 1 - Login JIRA
DEPRECATED JS - Cookie has been deprecated since 5.8.0 and will be removed in a future release. Use cookie instead.   
 No stack trace of the deprecated usage is available in your current browser.
Downloading resources:

DEPRECATED JS - Dropdown constructor has been deprecated and will be removed in a future release. Use Dropdown2 instead.   
 No stack trace of the deprecated usage is available in your current browser.
AG.LayoutManager.setLayout: Can't manipulate layout. Layout is not writable
Security tokens will be refreshed every 720000ms
DEPRECATED JS - Inline dialog constructor has been deprecated and will be removed in a future release. Use inline dialog 2 instead.   
 No stack trace of the deprecated usage is available in your current browser.
Downloading resources:
js!/s/d41d8cd98f00b204e9800998ecf8427e-T/bjk90u/72010/b6b48b2829824b869586ac216d119363/7aa44fa9aad9a6239c392b1e7bc884f4/_/download/contextbatch/js/browser-metrics-plugin.co
ntrib,-_super,-atl.dashboard,-atl.general/batch.js?agile_global_admin_condition=true&atlassian.aui.raphael.disabled=true&is-server-instance=true&jag=true&jaguser=true&jcap=
true&nps-not-opted-out=true&sd_operational=true!order
Downloading resources:
css!/s/10d963e1fcee333a7f9aebf08e9b202d-T/bjk90u/72010/b6b48b2829824b869586ac216d119363/329db972cd13259548cc14eada2ef26b/_/download/contextbatch/css/com.atlassian.jira.plug
ins.jira-development-integration-plugin:devstatus-dialog-resources-ctx,-_super,-atl.general,-atl.dashboard/batch.css?agile_global_admin_condition=true&atlassian.aui.raphael
.disabled=true&is-server-instance=true&jag=true&jaguser=true&jcap=true&nps-not-opted-out=true&sd_operational=true
js!/s/a0d3356f3721fb8694c9496f54f4b3ce-T/bjk90u/72010/b6b48b2829824b869586ac216d119363/329db972cd13259548cc14eada2ef26b/_/download/contextbatch/js/com.atlassian.jira.plugin
s.jira-development-integration-plugin:devstatus-dialog-resources-ctx,-_super,-atl.general,-atl.dashboard/batch.js?agile_global_admin_condition=true&atlassian.aui.raphael.di
sabled=true&is-server-instance=true&jag=true&jaguser=true&jcap=true&locale=en-US&nps-not-opted-out=true&sd_operational=true!order
forceLayoutRefresh() is deprecated. Use resize() instead.
forceLayoutRefresh() is deprecated. Use resize() instead.
forceLayoutRefresh() is deprecated. Use resize() instead.
forceLayoutRefresh() is deprecated. Use resize() instead.
Step 2 - Save login page
Stopped here/Didnt go further

What i need to change in the code ?

Harish P C
  • 107
  • 1
  • 15
  • It is maybe a good idea to do some _console.log(document.innerHTML)_ to make sure it is going through all the steps. Have a look http://code-epicenter.com/how-to-login-amazon-using-phantomjs-working-example/ you might find some ideas – kimy82 Dec 11 '17 at 08:17
  • I have added the console.log to get the details for each function(), I am not sure what this output conveying to me. Can you please help me on this? – Harish P C Dec 11 '17 at 09:22
  • Looks like the login page is not rendering into phantomJS – kimy82 Dec 11 '17 at 09:45
  • Its rendering only the first image which is page.png not the other one which is profil.png. I am not sure why it is not moving to next page.open. – Harish P C Dec 11 '17 at 09:56
  • I tried checking the following answer - https://stackoverflow.com/questions/30954345/phantomjs-open-one-page-after-another?noredirect=1&lq=1 and https://stackoverflow.com/questions/35965252/how-to-open-a-specific-url-in-a-session-after-login-in-phantomjs but none of them are working in my case. – Harish P C Dec 11 '17 at 10:50

0 Answers0