Скриншот узла Selenium DevTools Capture - PullRequest
0 голосов
/ 26 апреля 2018

Как использовать DevTools Capture с использованием Python? Здесь есть код, но я не знаю, как его использовать для скриншотов узлов.

def chrome_takeFullScreenshot(driver):
def send(cmd, params):
    resource = "/session/%s/chromium/send_command_and_get_result" % driver.session_id
    url = driver.command_executor._url + resource
    body = json.dumps({'cmd': cmd, 'params': params})
    response = driver.command_executor._request('POST', url, body)
    return response.get('value')

def evaluate(script):
    response = send('Runtime.evaluate', {'returnByValue': True, 'expression': script})
    return response['result']['value']

metrics = evaluate( \
    "({" + \
    "width: Math.max(window.innerWidth, document.body.scrollWidth, document.documentElement.scrollWidth)|0," + \
    "height: Math.max(innerHeight, document.body.scrollHeight, document.documentElement.scrollHeight)|0," + \
    "deviceScaleFactor: window.devicePixelRatio || 1," + \
    "mobile: typeof window.orientation !== 'undefined'" + \
    "})")
print metrics
print send('Emulation.setDeviceMetricsOverride', metrics)
screenshot = send('Page.captureScreenshot', {'format': 'png', 'fromSurface': True})
send('Emulation.clearDeviceMetricsOverride', {})
return base64.b64decode(screenshot['data'])
...