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. Spark log4j日志配置详解(转载)

    一.spark job日志介绍    spark中提供了log4j的方式记录日志.可以在$SPARK_HOME/conf/下,将 log4j.properties.template 文件copy为 l ...

  2. 石子合并(区间DP经典例题)

    题目链接:https://www.luogu.org/problemnew/show/P1880 #include <cstdio> #include <cmath> #inc ...

  3. Reveal使用

    本人手机是7.1的,reveal2.0以后不支持8.0以下,没办法,这里只能使用reveal1.6. 这里提醒一下,reveal2.0以后libReavel.lib改名了,. https://reve ...

  4. Cocos Code IDE (下载地址)

    Cocos Code IDE 1.2.0 下载地址       Cocos Code IDE 1.2.0 Win32 下载地址: http://www.cocos2d-x.org/filedown/c ...

  5. 开源unittest测试报告源码BSTestRunner.py

    开源BSTestRunner 生成HTML测试报告源码: 保存代码到BSTestRunner.py 配合Unittest使用,很完美. python2: """ A Te ...

  6. EasyTouch中虚拟摇杆的使用EasyJoystick

    unity3d自带的虚拟摇杆显然没有EasyTouch好用 首先下载这个插件 http://pan.baidu.com/s/1hqJAbTa 下载完成后.导入到unity,可以看看里面的案例

  7. “0x00,0x08”两个十六进制字符串,转换为整形

    int m_length=0;char buf[2]=={0x00,0x08};memcpy(&m_length,&buf[0],2); m_length=m_length<&l ...

  8. c++读入优化

    对于输入数据非常大的一些可(变)爱(态)题目,scanf就会大大拖慢程序的运行速度,cin就更不用说了,所以我们要用一种高大上的东西——读入优化. 读入优化的原理其实就是一个一个字符的读入,再组成数字 ...

  9. C++的类型转换

    一.类型转换名称和语法 1.C风格的强制类型转换(Type Cast)很简单,不管什么类型的转换统统是: TYPE b = (TYPE)a    2.C++风格的类型转换提供了4种类型转换操作符来应对 ...

  10. uvalive 4960 Sensor Network

    题意: 给出一个无向图,求一个生成树使得这个生成树的最大边与最小边之差最小,输出这个最小的差值.n的最大值为350. 思路: 这题不看题解想破头也不知道怎么写Orz. 暴力的做法是可以从大到小枚举边作 ...