Question

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 ?

Was it helpful?

Solution

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......");

OTHER TIPS

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);

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top