Handle Blocked Java Plugins in WebDriver Browsers
In this article
This guide explains how to configure Selenium WebDriver to handle browsers that block Java plugins, a common issue when automating legacy web applications that rely on Java applets. You'll learn to set browser preferences, use the right driver capabilities, and work around plugin restrictions without violating security policies.
What You'll Need
- Selenium WebDriver (Java, Python, C#, or JavaScript bindings)
- A browser that supports Java plugins (e.g., Firefox ESR, Internet Explorer 11, or Safari with Java enabled)
- Java Runtime Environment (JRE) installed on the machine running the tests
- Access to the browser's profile or preferences directory
Step-by-Step
- Identify the browser and its plugin blocking behavior. Modern browsers like Chrome and Edge no longer support NPAPI plugins, so Java applets won't run. Firefox ESR (Extended Support Release) and IE11 still support them, but may block by default. Check your target browser's version and security settings.
- Enable Java in the browser's native settings. For Firefox: go to about:config, set
plugin.scan.JavaApplettotrueandplugin.state.javato2(enabled). For IE: open Internet Options, Security tab, Custom level, and enable "Run ActiveX controls and plugins" under Java-related settings. - Create a browser profile with Java enabled. In Selenium, you can use a custom profile. For Firefox, use
FirefoxProfileand set preferences programmatically:FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("plugin.scan.JavaApplet", true); profile.setPreference("plugin.state.java", 2); WebDriver driver = new FirefoxDriver(profile);For IE, useInternetExplorerOptionswithEnableNativeEventsand ensure Java is enabled in the system's Java Control Panel. - Set driver capabilities to allow plugin execution. For Firefox, use
CapabilityType.ACCEPT_SSL_CERTSandCapabilityType.SUPPORTS_JSas needed, but there is no direct capability for Java plugins. For IE, setIntroduceInstabilityByIgnoringProtectedModeSettingstotrueif you encounter protected mode issues, but be cautious as this may lower security. - Handle the browser's click-to-play prompt. Some browsers block Java plugins with a placeholder. You can click the placeholder using WebDriver's
findElementandclick()method. For Firefox, the placeholder may be an element with a specific class or ID; you may need to use XPath to locate it. - Use browser-specific workarounds. For Firefox, you can set the preference
plugin.default.stateto2to always enable plugins. For IE, ensure the Java plug-in is listed in the "Manage Add-ons" and is enabled. For Safari, you must enable Java in Safari's Preferences > Security > Plug-in Settings. - Test with a simple Java applet page. Create a minimal HTML page with an applet tag and verify that WebDriver can interact with it. If the applet loads, your configuration is correct.
- Consider using a Selenium Grid node with a compatible browser. If you cannot modify the browser's security settings on the local machine, set up a dedicated node with an older browser version that supports Java and configure it as needed.
Common Mistakes
- Using a browser version that no longer supports NPAPI (e.g., Chrome 45+, Firefox 52+). Java plugins simply won't load.
- Forgetting to enable Java in the system's Java Control Panel, not just the browser.
- Setting preferences after the driver is instantiated; they must be set before creating the driver instance.
- Assuming that disabling protected mode in IE is safe; it can expose the browser to security risks.
- Overlooking the click-to-play placeholder; the applet won't load until you click it.
Tips
- Use Firefox ESR (Extended Support Release) for the most stable Java plugin support.
- Keep a separate browser profile for testing that has Java enabled, so you don't alter your default profile.
- If you're automating a large suite, consider testing the Java applet separately from the rest of your UI tests.
- Document the exact browser version and Java version you're using; compatibility issues are common.
- Use
WebDriverWaitto wait for the applet to load, as it may take a few seconds.
Troubleshooting
- Applet doesn't load at all: Check the browser's console for errors. Verify that Java is installed and the plugin is enabled. Try loading the applet manually in the same browser to see if it works outside WebDriver.
- WebDriver throws "Unsupported operation" error: This often means the browser doesn't support Java plugins. Switch to a compatible browser version or use a different approach like testing the applet with a separate tool.
- Click-to-play placeholder not found: Inspect the page source to find the exact element. It may be an
embedorobjecttag. Use XPath or CSS selectors to locate it. - Profile preferences not taking effect: Ensure you're using the correct preference names. For Firefox, check
about:configto see the exact keys. Also, make sure you're setting them on the profile object before passing it to the driver. - Java applet loads but is not interactive: Some applets require focus or a specific window. Use
driver.switchTo().window()if the applet opens a new window, or useActionsto click inside the applet area.
Frequently Asked Questions
Can I use Chrome to run Java applets with WebDriver?
No, Chrome removed NPAPI support in version 45. Java applets won't run in modern Chrome. Use Firefox ESR or IE11.
Do I need to install Java separately?
Yes, the Java Runtime Environment (JRE) must be installed on the machine where the browser runs. The browser plugin uses it to execute applets.
How do I know if my browser blocks Java plugins?
When you visit a page with an applet, you'll see a placeholder or a warning. In Firefox, you might see a "This plugin is disabled" message. You can also check the browser's add-ons or plugins manager.
Can I bypass the browser's security prompt to auto-load the applet?
Yes, by setting the appropriate preferences (e.g., plugin.state.java to 2 in Firefox) you can auto-enable the plugin. However, this reduces security, so only do it in a controlled test environment.
What if my applet requires a specific Java version?
You need to install that Java version and ensure the browser uses it. In the Java Control Panel, you can set the version used by the browser. WebDriver doesn't control this; it's a system setting.
Is there a way to run Java applets without a browser plugin?
No, Java applets require a browser plugin. If your browser doesn't support it, consider converting the applet to a web application or using a different automation approach like invoking the applet's underlying logic via API.