CodexBloom - Programming Q&A Platform

Selenium WebDriver flickering guide with browser window during tests on Chrome 115

๐Ÿ‘€ Views: 15 ๐Ÿ’ฌ Answers: 1 ๐Ÿ“… Created: 2025-07-17
selenium-webdriver chrome headless Java

This might be a silly question, but I'm wondering if anyone has experience with I'm working on a project and hit a roadblock... I'm refactoring my project and I'm working with a strange flickering scenario with the browser window when running tests using Selenium WebDriver on Chrome version 115. The tests are executed in headless mode, and the flickering primarily occurs during page transitions and element interactions. It makes it hard to capture screenshots since they often turn out blank or corrupted. I've tried using the `--disable-gpu` and `--no-sandbox` options when initializing the WebDriver, but it hasn't helped alleviate the scenario. Hereโ€™s how Iโ€™m setting up the Chrome options: ```java ChromeOptions options = new ChromeOptions(); options.addArguments("--headless"); options.addArguments("--disable-gpu"); options.addArguments("--no-sandbox"); WebDriver driver = new ChromeDriver(options); ``` I've also attempted to implement waits using `WebDriverWait` to ensure elements are present before interacting with them, but the flickering still continues. Hereโ€™s a snippet of how Iโ€™m currently using it: ```java WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); WebElement myElement = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("myElementId"))); myElement.click(); ``` This flickering isn't present when I run the tests in standard mode or on Firefox, which makes me think itโ€™s specific to Chrome in headless mode. Has anyone else faced this scenario or found a workaround to reduce or eliminate the flickering? Any insights would be greatly appreciated! I recently upgraded to Java stable. For reference, this is a production CLI tool. Any ideas how to fix this? My development environment is Debian. What am I doing wrong? I'm using Java 3.11 in this project.