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:
JavaScript
x
17
17
1
mobile_emulation = { "deviceName": "Pixel 2" }
2
opts = webdriver.ChromeOptions()
3
opts.add_argument("--log-level=3")
4
opts.add_argument("--headless")
5
6
opts.add_argument("--disable-extensions")
7
opts.add_argument("--disable-gpu")
8
opts.add_argument("--proxy-server=direct://")
9
opts.add_argument("--proxy-bypass-list=(")
10
opts.add_argument("window-size=1920x1080")
11
12
13
opts.add_experimental_option("mobileEmulation", mobile_emulation)
14
print("OPENING DRIVER:")
15
driver = Webdriver.Chrome(executable_path=r"C:binchromedriver.exe",options=opts)
16
17
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.
JavaScript
1
2
1
mobile_emulation = { "deviceName" : "iPhone X" }
2