与硒进行画布交互 [英] Interacting with a Canvas with Selenium

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

问题描述

我已经对此进行了一些阅读,但未能找到特定的内容.我有一个需要与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元素的问题.但它无法访问其内部元素/子元素.因为硒使用了DOM模型,并且canvas的子元素在DOM中不可见. 在查看此处的示例后,我们可以与使用坐标的画布.但这是荒谬的,在大多数情况下,我们将动态绘制元素,以及如何获取垂直形状的坐标. 如果您具有形状的坐标,则可以使用上面的链接与它们一起玩.

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.

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

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