https://stackoverflow.com/questions/43609429/how-to-get-text-inside-a-canvas-using-webdriver-or-protractor

https://sqa.stackexchange.com/questions/3253/how-to-automate-the-action-on-a-canvas-object-when-the-canvas-element-has-no-na

0

To work inside a canvas you can use the Kantu web automation software or Sikuli. Both solutions are based on screenshots, image comparison and OCR, and can get the text inside the canvas.

You mark the data that you want to extract ("scrape") by drawing pink frames around it. Kantu then retrieves the data by using OCR. With Sikuli, you would need to find out the coordinates first.

Or, as JeffC suggested, use your current software to take a screenshot, and then OCR it. For OCR, there is the well-known Tesseract lib or use an online service like the free ocr.space.

1

The basics are that you can't with Selenium. the CANVAS tag is like an applet in the page. It doesn't actually contain any HTML. There are a few options:

  1. If you have access to the devs, you can have them expose an API for you so that you can access text, etc. using Javascript from your Selenium script. If it's part of some library, etc. the library itself may provide an API that you can use. This is the most reliable option.

  2. For executing actions, you can use coordinates. You can base all click, etc. actions off coordinates but this is highly dependent on the browser rendering, screen resolution, etc. This will not help you get text out of the CANVAS though.

  3. For the text, you really don't have any options to get the text directly. You could take screenshots and verify the text after the run is complete but that's about your best option. If you wanted to get really fancy, depending on the text, etc. you may be able to find an OCR library that will be able to extract the text from the screenshot that you took.

Canvas does not separate the graphics it drew included text. You need OCR. You may use a tool to cut the canvas image to clipboard and invoke a program to paste the image to preprocess, and perform OCR. Image preprocessing will extract the region of interest which is the text to improve OCR accuracy.

How to Get Text inside a Canvas using Webdriver or Protractor的更多相关文章

  1. jsp报错问题之“使用jstl的c标签choose报错Illegal text inside "c:choose" tag问题”

    一.报错 [bessky_it][ERROR][2022-03-25 17:19:07] | PLATFORM | ):[c]鍜孾/com.bessky.pss.portal/purchase/sam ...

  2. Html5 Canvas Text

    html5 canvas中支持对text文本进行渲染;直接的理解就是把text绘制在画布上,并像图形一样处理它(可以加shadow.gradient.pattern.color fill等等):既然它 ...

  3. 在canvas上面拖拽对象。

    原文:https://html5.litten.com/how-to-drag-and-drop-on-an-html5-canvas/ 下面作者的原始的版本会抖动一下(鼠标刚点下去的时候,位置会发生 ...

  4. H5 canvas的 width、height 与style中宽高的区别

    Canvas 的width height属性 1.当使用width height属性时,显示正常不会被拉伸:如下 <canvas id="mycanvas" width=&q ...

  5. HTML5移动开发学习笔记之Canvas基础

    1.第一个Canvas程序 看的是HTML5移动开发即学即用这本书,首先学习Canvas基础,废话不多说,直接看第一个例子. 效果图为: 代码如下: <!DOCTYPE html> < ...

  6. canvas调用scale或者drawImage图片操作后,锯齿感很明显的解决

    <script type="text/javascript"> //解决canvas画画图片 var mengvalue = -1; var phoneWidth = ...

  7. 用Canvas实现动画效果

    1.清除Canvas的内容 clearRect(x,y,width,height)函数用于清除图像中指定矩形区域的内容 <!doctype html> <html> <h ...

  8. Canvas制作天气预报走势图

    要实现的效果如下图: HTML代码如下: ;;;;;;;;;;; }

  9. html5、canvas绘制本地时钟

    效果图: 代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

随机推荐

  1. [js]js的表单验证

    http://uule.iteye.com/blog/2183622 表单验证类 <form class="form" method="post" id= ...

  2. wordvector to sentence vector

    wordvector已经通过word2vec训练出来了,可是如何通过WV得到SV(Sentence Vector)? 思路1: 直接将句子的向量叠加取平均:效果很不好,每个词没有考虑权重,获取的向量会 ...

  3. extjs store快速创建的几种方式

    viewModel中定义stores: { tickets: { model: 'Ticket', autoLoad: true, remoteFilter: true, filters: [{ pr ...

  4. Photoshop去图片水印——适用复杂图片上有水印

    该方法适合复杂图片上有水印的,不过这个只适合水印只是文字而没有背景的那种.不是所有的水印图片都适合处理.下面是处理前后的对照   工具/原料   photoshop8.0 方法/步骤   1 打开需要 ...

  5. MySQL学习笔记--启动停止服务

    右键点击计算机->管理->服务  windows所有的服务都在,mysql等等.可以在这里启动停止服务也可以在命令行 net start/stop  <服务名> InnoDB还 ...

  6. cocos2d-x JS 四人麻将中的服务器位置与客户端位置转换相关

    前言:在写各类游戏编程中,都会遇到一个问题,就是位置问题,服务端的位置是与客户端的位置是不同的,这中间需要进行一个转化,客户端一套代码运行,不管是任何人登陆,该位置始终都是在屏幕正下方,所以这样就要进 ...

  7. Linux rz命令无效

    rz命令无效 我习惯使用SecureCRT工具,进行远程连接Linux服务器,在进行文件传输的时候,可以使用sftp (alt+p)方式进行传输文件,也经常使用rz命令进行图形化的方式传输文件. 当r ...

  8. jQuery绑定事件方法及区别(bind,click,on,live,one)

    第一种方式: ? 1 2 3 4 5 $(document).ready(function(){  $("#clickme").click(function(){  alert(& ...

  9. notepad使用列选

    列选有两种方法: 1.按住ALT + 鼠标从某点按住开始向下或向上拖动. 2.按住ALT+SHIFT+上下方向键. 列编辑: 1.ALT+C 2.插入相同文本还是自增数字

  10. 如何运行ruby代码

    第一种,ruby -e 在命令行中运行下面命令,-e的意思是,把后面的字符串当作脚本执行 ruby -e "print 'hello'" 使用irb交互控制台 在命令行输入irb ...