9

While using FirefoxDriver to write tests,

I discovered loading of pages are really slow because of javascript and css being executed. IS there anyway to disable this ? possible to even install Noscript plugin to profile ?

additionally, sendKeys(), actually types out the text. however, this is quite slow for long text, anyway to instantly type all the string int othe input box ?

2
  • 1
    You are subverting WebDriver by making the whole string appear at once. WebDriver is designed to emulate a user, a user doesn't magically make text appear, they type it out. It may take slightly longer but it is an accurate emulation of a real person.
    – Ardesco
    Feb 7, 2012 at 14:11
  • If you disable JS, CSS, the whole page might break so that some functional testing that you are going to execute by Selenium WebDriver might interrupted. The purpose of testing is Functional, not Performance. Apr 10, 2014 at 7:58

3 Answers 3

17

You can disable javaScript in FirefoxProfile:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("javascript.enabled", false);
WebDriver driver = new FirefoxDriver(profile);

I do not think that there's a way to disable CSS and this not what you should do - this may break your web application, and disabling JavaScript may do this too.

There's no way to set the value of the text field directly - WebDriver is designed to simulate the real user "driving" the browser - that's why there's only sendKeys.

However you can set the value of the element via JavaScript call (if you will not disable it, of course). This is faster for the long test, but this is not the emulation of the user interaction so some validations may not be triggered, so use with caution:

private void setValue(WebElement element, String value) {
    ((JavascriptExecutor)driver).executeScript("arguments[0].value = arguments[1]", element, value);
}

and use it:

WebElement inputField = driver.findElement(By...);
setValue(inputField, "The long long long long long long long text......");
13

See also Do not want images to load and CSS to render on Firefox in Selenium WebDriver tests with Python

To hide CSS and images:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("permissions.default.stylesheet", 2);
profile.setPreference("permissions.default.image", 2);
FirefoxDriver browser = new FirefoxDriver(profile);
0

Also you can use PhantomJS is WebKit browser without User Interface so it is really faster than FireFox or Chrome. There is web driver support for PhantomJS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.