使用 Selenium 与 Canvas 交互 [英] Interacting with a Canvas with Selenium

查看:119
本文介绍了使用 Selenium 与 Canvas 交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此进行了一些阅读,但无法找到具体的内容.我有一个需要与 Selenium 交互的画布对象.然而,众所周知,画布对象就像一个封闭的盒子.我读到您可以在画布内绘制的 JS 代码中添加钩子",以允许 Selenium 捕获这些钩子并处理某些事情.

I've done a bit of reading on this, but haven't been able to find something specific. I have a canvas object that I need to interact with, with Selenium. However as we all know canvas objects are like a closed box. I read that you can add 'hooks' in the JS code that draws inside the canvas to allow Selenium to catch these hooks and work with certain things.

但我不确定我该怎么做.有没有人愿意分享任何经验或小例子?

But I'm not sure how I could go about this. Does anyone have any experience or a small example they would be willing to share?

推荐答案

我也在研究同样的问题,搜索了一段时间后我了解到 Selenium 访问 canvas 元素.但它无法访问它的内部元素/子元素.因为 selenium 使用了 DOM 模型,并且 canvas 的子元素在 DOM 中是不可见的.在查看了此处中提到的一个示例后,我们可以与使用坐标的画布.但这很荒谬,大多数时候我们会动态地绘制元素,我们如何获得perticular shape的坐标.如果你有形状的坐标,你可以使用上面的链接玩它们.

I was also looking into the same issue, after searching for some time I understood that Selenium accesses canvas element. but it can't access the inner elements/child elements of it. Because selenium used DOM model and canvas's child elements wont visible in DOM. After looking into one example mentioned here, we can interact with the canvas using coordinates. But that's absurd, most of the times we will draw elements dynamically, and how can we get perticular shape's coordinates. If you are having coordinates of the shapes you can play with them using above link.

这篇关于使用 Selenium 与 Canvas 交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆