使用Watir启用Firefox Flash及自动登录失败求助
Hey there! I totally get how frustrating this can be—you’ve got your Watir script set up, the steps run fine, but then that Flash error pops up out of nowhere. Let’s break down how to fix this, since Firefox has pretty strict defaults around Flash these days.
First, let’s cover the core issue: Firefox disables Flash by default, even if you think your "default" profile has it turned on. Watir might not be loading your regular user profile correctly, or the profile’s Flash settings aren’t actually applied when running automation. Here are a few actionable solutions:
1. Manually Verify & Configure Your Default Firefox Profile
If you want to stick with your existing default profile, double-check these settings in your regular Firefox browser (not the one launched by Watir):
- Go to
about:addons→ Plugins → Find Adobe Flash Player → Set it to Always Activate. - Head to
about:config(click "Accept the Risk and Continue" if prompted):- Search for
plugin.state.flash→ Set its value to2(this means "Always enable"). - Search for
plugins.click_to_play→ Set tofalseto skip the "click to activate" prompt. - For Linux, check
dom.ipc.plugins.enabled.libflashplayer.soand set totrue; for Windows/Mac, look for the corresponding Flash plugin key and enable it.
- Search for
After updating these, close Firefox completely and run your script again—Watir should load the updated profile settings.
2. Create a Custom Profile in Your Script (More Reliable)
Using a custom profile ensures your Flash settings are always applied, no matter what your default profile’s state is. Modify your code like this:
# Create a dedicated Firefox profile for automation profile = Selenium::WebDriver::Firefox::Profile.new # Enable Flash globally profile['plugin.state.flash'] = 2 # Disable click-to-play prompts for Flash profile['plugins.click_to_play'] = false # Allow Flash to run on your target site (add more sites if needed) profile['plugin.exceptions.adobe-flashplayer'] = 'https://my.test.site.com/,*' # Enable the Flash plugin process (adjust based on your OS if needed) profile['dom.ipc.plugins.enabled.libflashplayer.so'] = true # Launch the browser with this custom profile ff = Watir::Browser.new :firefox, profile: profile, accept_insecure_certs: true ff.goto 'https://my.test.site.com/' ff.driver.manage.window.maximize ff.text_field(id: 'login').set 'mytestuser@domain.com' ff.text_field(id: 'password').set 'Password' ff.button(text: 'Log In').click
3. Check Your Firefox Version
Important note: Adobe stopped supporting Flash in 2020, so modern Firefox versions (post-ESR 52) don’t include Flash support at all. If you’re using a newer Firefox, you’ll need to switch to Firefox ESR 52 (the last version that supports Flash) and install the corresponding Flash Player plugin for that version.
Give these steps a try—most likely, either configuring the profile correctly or using a custom profile will resolve that error. Let me know if you hit any snags!
内容的提问来源于stack exchange,提问作者rickman

