Java Robot:如何在浏览器中点击第一个文本(使用搜索功能)?(Java Robot : how to click on first text highlighted (using the se

编程入门 行业动态 更新时间:2024-10-22 22:57:37
Java Robot:如何在浏览器中点击第一个文本(使用搜索功能)?(Java Robot : how to click on first text highlighted (using the search function) in a browser?)

我正在构建一个java机器人,在浏览器中搜索关键字之后,鼠标将直接移动到此关键字的这个实例(突出显示)。

我的问题是我不知道位置(x,y)提前我不能使用mouseMove(x,y)。

在此先感谢您的帮助。

I am building a java robot that after a search of a keyword in a browser the mouse will move directly to this instance of this keyword (which is highlighted).

My problem is a I do not know the position (x,y) in advance I cannot use mouseMove(x,y).

最满意答案

假设您不想在Java中从头开始重写浏览器,唯一的方法是使用Robot.createScreenCapture()创建BufferedImage,然后迭代图像的像素以找到突出显示颜色。

问题是浏览器窗口中的其他内容可能是那种颜色,在这种情况下,您必须更聪明才能到达正确的位置。

无耻的自我推销:前一段时间我创建了一个完全相同的程序,以便自动点击Pandora上的“我仍在听”按钮。 Pandora后来改变了按钮的外观,因此它不再起作用,但是如果你想查看代码仍然可用: http : //staticvoidgames.com/games/StillListening

编辑:这也假设高亮颜色始终相同。 你可能想在潜入之前检查一下这个假设。

The only way to do this, assuming you don't want to rewrite a browser from scratch in Java, is to use Robot.createScreenCapture() to create a BufferedImage, then iterate over the pixels of the image to find the highlight color.

The problem is that other things in the browser window might be that color, in which case you'll have to be more clever to go to the correct place.

Shameless self-promotion: A while ago I created a program that did exactly that, in order to automatically click the "I'm Still Listening" button on Pandora. Pandora has since changed the look of their button so it doesn't work anymore, but the code is still available if you want to check it out: http://staticvoidgames.com/games/StillListening

Edit: This also assumes that the highlight color is always the same. You might want to check that assumption before diving in.

更多推荐

本文发布于:2023-04-27 16:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1327166.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第一个   搜索功能   器中   文本   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!