The mobile_emulation
capability was added to ChromeDriver in 2.11
Full documentation: https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation
My notes below:
Creating a driver in Python with the mobile_emulation capability options:
driver = self.CreateDriver(
mobile_emulation = {
'deviceMetrics': {'width': 360, 'height': 640, 'pixelRatio': 3}})
Currently you can emulate devicepixelratio, useragent, viewport height and width.
Possible properties for the mobile_emulation dict:
deviceName
: if used, must be the only property. Matches a device preset in Chrome (e.g. 'Google Nexus 5'
).
deviceMetrics
: a dict that can include width (int), height (int), pixelRatio (double) as shown above.
userAgent
: a string to spoof at the request header and navigator object.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…