ClericPy / ichrome

Chrome controller for Humans, based on Chrome Devtools Protocol(CDP) and python3.7+.
https://pypi.org/project/ichrome/
MIT License
228 stars 29 forks source link

how to upload files? #43

Closed snja closed 3 years ago

snja commented 3 years ago

if on selenium use send_keys, Has anyone ever used this Ichrome successfully?

ClericPy commented 3 years ago

uploading files is not a common feature, I prefer to usingDOM.setFileInputFiles like this (shopify uploader)

        root_id = (await
                   tab.send('DOM.getDocument'))['result']['root']['nodeId']
        nodeId = (await
                  tab.send('DOM.querySelector',
                           nodeId=root_id,
                           selector='input[type="file"]'))['result']['nodeId']
        await tab.send('DOM.setFileInputFiles',
                       files=[str(path.absolute())],
                       nodeId=nodeId)

If you really need the send_keys method, try the tab.keyboard_send method