I’m using selenium with python and I have a problem: I want to get pixel color of x y position on canvas.
Does Selenium have some color picker or something similar?
I tried get color of a pixel with getCssValue but it doesn’t work because it is canvas.
This is an example what I’m trying to achieve
JavaScript
x
27
27
1
from selenium import webdriver
2
from selenium.webdriver.chrome.options import Options
3
from selenium.webdriver.common.action_chains import ActionChains
4
from selenium.webdriver.common.keys import Keys
5
import time
6
chrome_options = Options()
7
8
prefs = {'profile.default_content_setting_values': {'images': 1,
9
'plugins': 2, 'geolocation': 2,
10
'notifications': 2, 'auto_select_certificate': 2, 'fullscreen': 2,
11
'mouselock': 2, 'mixed_script': 2, 'media_stream': 2,
12
'media_stream_mic': 2, 'media_stream_camera': 2, 'protocol_handlers': 2,
13
'ppapi_broker': 2, 'automatic_downloads': 2, 'midi_sysex': 2,
14
'push_messaging': 2, 'ssl_cert_decisions': 2, 'metro_switch_to_desktop': 2,
15
'protected_media_identifier': 2, 'app_banner': 2, 'site_engagement': 2,
16
'durable_storage': 2}}
17
chrome_options.add_experimental_option('prefs', prefs)
18
chrome_options.add_argument("disable-infobars")
19
chrome_options.add_argument("disable-gpu")
20
21
driver = webdriver.Chrome(options=chrome_options, executable_path=r"C:geckochromedriver.exe")
22
driver.get("https://drawisland.com/")
23
24
act = ActionChains(driver)
25
canvas = driver.find_element_by_tag_name("canvas")
26
act.move_to_element_with_offset(canvas,100,100).GetColor().perform()
27
Advertisement
Answer
This is apparently not possible directly with selenium.