Enable JavaScript in PhantomJS with C# -


i've used phantomjs in c# application , it's not executing javascript though property phantomjsdriver.capabilities.isjavascriptenabled true. simple page below still executes content of noscript tag. how can make phantomjs execute javascript?

i've added selenium , phantomjs vs2012 solution via nuget:

pm> install-package selenium.webdriver  pm> install-package phantomjs  

i've created simple html page demonstrate javascript not enabled:

<html>   <body>     <a href="javascript:gotoanotherpage()">go page</a>     <noscript>       no javascript!     </noscript>   </body> </html> 

i've used phantomjsdriver. src displays "no javascript!"

public class program {     public static void main(string[] args)     {         var phantomdriver = new phantomjsdriver();         phantomdriver.url = @"c:\page.html";         var src = phantomdriver.pagesource;     } } 

javascript default enabled when using phantomjs. in fact i'm not aware webdriver starts browser without javascript default.

to make sure javascript enabled, can check

var phantomdriver = new phantomjsdriver(); var enabled = phantomdriver.capabilities.isjavascriptenabled; 

you can check experimentally javascript running taking screenshot , checking noscript block not shown. when screenshot (phantomdriver.getscreenshot();) blank in case works.

it way bad idea disable javascript phantomjsdriver, because many operations of webdriver protocol implemented in javascript. disabling js disable driver.


Comments

Popular posts from this blog

c# - how to use buttonedit in devexpress gridcontrol -

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - System.FormatException' occurred in MongoDB.Bson.dll - XXX is not a valid 24 digit hex string -