Element not identified when not being focus on chrome window in Selenium

Question:

I am trying to make a whatsapp bot, when the user opens other programs on the whatsapp window and this whatsapp window loses focus, it doesn’t get some elements right. I tried to use headless but it now doesn’t see any elements. Can someone help me?

Asked By: Omar Yacop

||

Answers:

Have you set the screen size?
The default screen size for headless mode is significantly smaller than the default screen size in regular mode.
Try setting it as following:

driver.set_window_size(1920, 1080)

Or via the options parameters:

options.add_argument("--window-size=1920,1080")
Answered By: Prophet
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.