When I tried to open one of our internal application's webpage(which works on IE8) using phantomjs, 'page.content' is showing below html message. However, page.render("test.png") is showing the completely loaded page. I have set the page.settings.useragent to Why is the discrepancy between .render() and .content? How to debug/resolve this issue?
HTML output:
<html>
<frameset id="mainFrameSet" border="0" frameborder="yes" framespacing="1" rows="37px,*" topmargin="0" leftmargin="0" bordercolor="#cdcdcd">
<frame name="header" src="<src>" frameborder="0" marginheight="0" bordercolor="#cdcdcd" marginwidth="0" noresize="" scrolling="no" bor
der="0">
<frame frameborder="0" border="0" name="main" id="main" src="<src>" bordercolor="#cdcdcd" scrolling="auto" leftmargin="0">
<noframes>
<BODY>
<P>This page uses frames, but your browser doesn't support them.</P>
</BODY>
</noframes>
</frameset>
</html>
my code:
var page = require("webpage").create(), testindex = 0, loadInProgress = false;
page.settings.javascriptEnabled = true;
page.settings.localToRemoteUrlAccessEnabled = true;
page.settings.XSSAuditingEnabled = true;
page.viewportSize = { width: 1366, height: 768 };
page.settings.userAgent = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)';
//Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB7.4; InfoPath.2; SV1; .NET CLR 3.3.69573; WOW64; en-US)
//Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)
//Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.8 Safari/534.34
//Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
//Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0)
//Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)
//SpecialAgent
//Load Login Page
page.open("<URL>");
window.setTimeout(function(){
enterLoginCredentials();
},10000);
function enterLoginCredentials (){
//Enter Credentials
page.evaluate(function() {
console.log("Loading login page..: " + url);
var uName = document.getElementsByName("username");
var uPass = document.getElementsByName("password");
uName[0].value="username";
uPass[0].value="password";
});
window.setTimeout(function(){
clickLogin();
},1000);
}
function clickLogin(){
//Login
page.evaluate(function() {
var formSubmit = document.forms["loginForm"];
formSubmit.submit();
});
window.setTimeout(function(){
search();
},10000);
page.render("LRMLogin111.png");
}
function search(){
page.render("Homepage.png");
console.log("Homepage "+page.content);
phantom.exit();
}
Some pages use frames even today. In contrast to the developer tools of your browser of choice PhantomJS doesn't include the DOM of the child frames in the main DOM. See for example this question which tries to overcome this: Dump HTML of page including iframes.
If you actually want to print and manipulate the child frames you have to switch to them. This is usually done with
page.switchToFrame
. To get the content, you can log thepage.frameContent
property.