python - Selenium - 如何在画布上的 XY 位置找到像素的颜色?
问题描述
我在 python 中使用 selenium,我有一个问题:我想在画布上获取 xy 位置的像素颜色。
Selenium 是否有一些颜色选择器或类似的东西?
我尝试使用 getCssValue 获取像素的颜色,但它不起作用,因为它是画布。
这是我想要实现的一个例子
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
import time
chrome_options = Options()
prefs = {'profile.default_content_setting_values': {'images': 1,
'plugins': 2, 'geolocation': 2,
'notifications': 2, 'auto_select_certificate': 2, 'fullscreen': 2,
'mouselock': 2, 'mixed_script': 2, 'media_stream': 2,
'media_stream_mic': 2, 'media_stream_camera': 2, 'protocol_handlers': 2,
'ppapi_broker': 2, 'automatic_downloads': 2, 'midi_sysex': 2,
'push_messaging': 2, 'ssl_cert_decisions': 2, 'metro_switch_to_desktop': 2,
'protected_media_identifier': 2, 'app_banner': 2, 'site_engagement': 2,
'durable_storage': 2}}
chrome_options.add_experimental_option('prefs', prefs)
chrome_options.add_argument("disable-infobars")
chrome_options.add_argument("disable-gpu")
driver = webdriver.Chrome(options=chrome_options, executable_path=r"C:\gecko\chromedriver.exe")
driver.get("https://drawisland.com/")
act = ActionChains(driver)
canvas = driver.find_element_by_tag_name("canvas")
act.move_to_element_with_offset(canvas,100,100).GetColor().perform()
解决方案
这显然不可能直接使用硒。
推荐阅读
- sql - 如何让我的日期与每周的开始/结束正确对齐?
- docker - 权限被拒绝执行 shell 脚本 - GitHub Actions
- sympy - SYMPY:如何简化 sqrt 比率?
- python - Python Tweepy Bot 从 json 文件中随机发送图像和相应的文本标题
- python - 如何正确地将文件中的单词转换为元组或列表
- javascript - 如何以编程方式检测网站的可用语言版本(区域设置)?
- javascript - 尝试向此脚本添加一个按钮,以便在单击时生成数字。我也不希望数字以相同的顺序重复
- c# - 我需要通过 ConnectionString 将我的 ASP.net MVC 项目连接到我的 Google Cloud SQL/PgAdmin 4
- mysql - Docker 编写 SpringBoot Mysql
- javascript - 如何在 React JS 中的页面刷新时选中持久复选框?