Selenium can't find an element unless a screenshot is taken right before

35 views
Skip to first unread message

Avram Eisner

unread,
Jun 12, 2025, 7:28:16 PMJun 12
to Selenium Users
Our team is trying to move from Create React App to Vite. Unfortunately, a lot of our existing selenium tests fail when we use the Vite dev server or production build and run them in headless mode (they all pass if Chrome is actually opened for the tests). There is a weird fix though - if we call driver.get_screenshot_as_base64() or some other screenshot method, then Selenium is able to find the element and the test passes. I've tried many other things like changing the headless browser window size and passing in a user-agent string but none of them have worked. We would like to fix the issue without resorting to a hack like the screenshot fix. Any ideas on how to fix this?

Zoltán Lehóczky

unread,
Jun 27, 2025, 12:17:38 PMJun 27
to Selenium Users
Taking a screenshot is a reported workaround for navigation issues in Chrome (that may have manifested due to Chrome's performance management becoming more aggressive). See https://groups.google.com/g/selenium-users/c/vfG6A6XVkA0 for tips.
Reply all
Reply to author
Forward
0 new messages