Electron 9.0.3升级后Selenium测试遇SessionNotCreatedException求助
Hey there, let's work through this frustrating issue you're hitting after upgrading Electron to 9.0.3. The "session not created from tab crashed" error usually ties to compatibility mismatches or missing critical launch arguments, so let's break down actionable fixes tailored to your tech stack:
1. Match ChromeDriver to Electron's Built-in Chromium Exactly
Electron 9.0.3 ships with Chromium 83.0.4103.99, and ChromeDriver requires a precise version match for stable communication. You mentioned trying 83.0.4103.39 and above, but make sure you're using the ChromeDriver build that corresponds to Chromium's full version number (83.0.4103.99).
For Electron-specific drivers, use the exact 9.0.3 version from the Electron mirror—avoid using 9.0.2 since even minor patch versions can introduce compatibility gaps.
2. Add Electron-Specific Launch Arguments
Your current arguments help with sandbox issues, but Electron 9.x needs additional flags to prevent window crashes. Update your ChromeOptions setup like this:
ChromeOptions options = new ChromeOptions(); options.setBinary(PathsAndVariables.toDvcAppDeep); // Critical Electron-specific flags options.addArguments("--remote-debugging-port=9222"); // Forces a fixed debug port to avoid conflicts options.addArguments("--disable-gpu"); // Disables GPU acceleration, a common crash trigger in Electron 9 options.addArguments("--disable-software-rasterizer"); // Complementary to GPU disable options.addArguments("--window-size=1920,1080"); // Sets a consistent window size to avoid rendering glitches // Keep your existing sandbox fixes options.addArguments("--no-sandbox"); options.addArguments("--disable-dev-shm-usage"); System.setProperty("webdriver.chrome.driver", PathsAndVariables.toWebDriver); driver = new ChromeDriver(options); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
3. Downgrade Selenium to a Stable Version
Selenium 4.0.0-alpha-6 is an early test build and may have unpolished support for Electron 9. Roll back to Selenium 3.141.59—the latest stable release—since it's widely tested with Chromium 83 and Electron 9.x.
Update your Gradle dependency to:
implementation 'org.seleniumhq.selenium:selenium-java:3.141.59'
4. Validate App Permissions and Paths
- macOS: Ensure your Electron app isn't blocked by system security settings. Right-click the app and select "Open" once to bypass Gatekeeper restrictions. Also, confirm
PathsAndVariables.toDvcAppDeepis an absolute path with no spaces or special characters. - Windows: Run your test suite with administrator privileges—Electron 9 may require elevated access to launch correctly under Selenium.
5. Enable Electron Debug Logs to Diagnose Crashes
Add these flags to your ChromeOptions to get detailed crash logs from Electron:
options.addArguments("--enable-logging"); options.addArguments("--v=1"); // Sets verbose logging level
Run your test again and check the console output—look for errors related to missing modules, permission denials, or rendering failures. This can pinpoint exactly why the window is crashing.
6. Rule Out SikuliX Interference
SikuliX relies on screen capture and may interact with Electron 9's updated rendering engine unexpectedly. Temporarily comment out all SikuliX-related code in your test suite and run just the Selenium setup. If the app stops crashing, you'll need to check for SikuliX updates compatible with Electron 9.
Give these steps a try in order—start with version matching and argument adjustments, as those are the most common fixes for this error.
内容的提问来源于stack exchange,提问作者Alex

