Reputation: 2093
When I open a page with Selenium 2.39.0 and Firefox 26/27, I get the content of the <noscript>
tag, so I need to enable javascript somehow. There are tons of materials on how to enable/disable javascript with FirefoxDriver and FirefoxProfile, but I cannot use this approach. Here's why: Selenium fails to open page on localhost
I need to enable javascript when using Selenium "the old way" like this:
browser = new DefaultSelenium("localhost", 4444, "*firefox", "http://localhost/");
How can I do this?
Upvotes: 3
Views: 8473
Reputation: 456
If you're using Firefox, you're best of creating a custom profile within Firefox to use to run your scripts. You can configure the profile to have JavaScript disabled for the duration of the test.
Exit firefox and then in a terminal type "firefox -P" to open the profile manager. You can then create one and switch between them (note, all instances of firefox need to be closed for this to appear). Simply disable JS in the profile you wish to use and you're away!
Alternatively, you could create the profile in your code and disable JS directly using the following code:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("javascript.enabled", false);
WebDriver driver = new FirefoxDriver(profile);
Upvotes: 1