-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting chrome devtool's "emulation/default-background-color-override" #359
Comments
@carlhu, I too am enjoying Etaoin (thanks @igrishaev!). And I too was wondering how to take a screenshot with a transparent background. from selenium import webdriver
import json
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)
if response['status']: raise Exception(response.get('value'))
return response.get('value')
options = webdriver.ChromeOptions()
options.add_argument("disable-gpu")
options.add_argument("disable-infobars")
driver = webdriver.Chrome(chrome_options=options)
driver.get("http://www.bbc.co.uk/news")
# take screenshot with a transparent background
send("Emulation.setDefaultBackgroundColorOverride", {'color': {'r': 0, 'g': 0, 'b': 0, 'a': 0}})
driver.get_screenshot_as_file(r"C:\temp\screenshot.png")
send("Emulation.setDefaultBackgroundColorOverride") # restore The etaion API includes an (etaoin/execute {:driver driver
:method :post
:path [:session (:session driver) "chromium" "send_command_and_get_result"]
:data {:cmd "Emulation.setDefaultBackgroundColorOverride"
:params {:color {:r 0 :g 0 :b 0 :a 0}}}}) Which I follow with my particular screenshot request: (etaoin/screenshot-element driver
{:tag :div :class :wrapper}
(str target-dir "/" github-id ".png")) And it seems to work! |
lread
added a commit
to lread/etaoin
that referenced
this issue
Jun 20, 2022
lread
added a commit
that referenced
this issue
Jun 20, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Etaoin's api is beautifully designed: thank you so much for sharing this.
I'd like to use the api's element capture api (which works great) except with transparent background. When I use the devtool protocol directly, setting the
emulation/set-default-background-color-override
to some color with alpha 0 works great. But I can't figure out how to use etaoin to do execute a (in Selenium's terms) acdp
command. Can you offer any guidance?If it helps, here is the java from their docs:
The text was updated successfully, but these errors were encountered: