Skip to content
Advertisement

Selenium – can not find element in headless mode

When I run my selenium program normally it works, but when I turn on the headless mode it does not find an element. I am using these driver options:

mobile_emulation = { "deviceName": "Pixel 2" }
opts = webdriver.ChromeOptions()
opts.add_argument("--log-level=3")
opts.add_argument("--headless")
        
opts.add_argument("--disable-extensions")
opts.add_argument("--disable-gpu")
opts.add_argument("--proxy-server=direct://")
opts.add_argument("--proxy-bypass-list=(")
opts.add_argument("window-size=1920x1080")


opts.add_experimental_option("mobileEmulation", mobile_emulation)
print("OPENING DRIVER:")
driver = Webdriver.Chrome(executable_path=r"C:binchromedriver.exe",options=opts)

I am working in python. I added those options in between because someone said that it would help, but it does not.

Advertisement

Answer

When I change the device name form Pixel 2 to iPhone X it works.

mobile_emulation = { "deviceName" : "iPhone X" }
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement