简体   繁体   English

如何在Sikuli获取图像的坐标?

[英]How to get the coordinates of an image in Sikuli?

I have this GUI on our project (please bear with my illustration, I'm not allowed to take a screenshot at work) 我在我们的项目上有这个GUI(请忍受我的插图,我不允许在工作时截取屏幕截图)

----------------------------------------------
    (1)     Header                            |
----------------------------------------------|
             (2)      Files             | (3) | Drop-down button (Options)
----------------------------------------|-----|          
                                        |     |
----------------------------------------|-----|
                                        |     |
----------------------------------------|-----|
                                        |     |
-----------------------------------------------

I need to test one file in each file type our product can support. 我需要测试我们的产品可以支持的每种文件类型中的一个文件。 The ultimate goal is to use that (3) drop down button. 最终目标是使用(3)下拉按钮。 Here is the summary of my code when I'm in this part 以下是我在这部分时的代码摘要

find_filetype = find.imagedict(filetypeicon.png) #(2) filetype

freg = find_filetype.right()

if freg.exists(drop-down.png):                   #(3) drop-down icon
    freg.click(drop-down.png)

Now after clicking (3), a drop-down menu with 4 action items will appear. 现在点击(3)后,将出现一个包含4个操作项的下拉菜单。 So for example if I click (3a): it will appear below from (3b - 3d) showing at least 2-3 drop-down items. 因此,例如,如果我单击(3a):它将显示在(3b - 3d)下方,显示至少2-3个下拉项。

----------------------------------------------
            Header                            |           
----------------------------------------------|
                                        | (3a)|
----------------------------------------------|
                                |  (a1)   |   |   #a1 = action 1
--------------------------------|---------|---|   
                                |  (a2)   |   |   #a2 = action 2
--------------------------------|---------|---|
                                |__(a3)___|   |
-----------------------------------------------

If I click (3c): The drop-down menu will choose to appear above (fad) Showing at least 2 drop-down items. 如果我点击(3c):下拉菜单将选择显示在上方(时尚)显示至少2个下拉项目。

----------------------------------------------
            Header                            |           
----------------------------------------------|
                                |  (a1)   |   |
--------------------------------|---------|---|         
                                |  (a2)   |   |
--------------------------------|_________|---|
                                        | (3c)|           
----------------------------------------|-----|
                                        |     |
----------------------------------------------

My workaround for this are : 我的解决方法是:

  1. screenshot all action items and 截图所有行动项目和

  2. if/elifs + dragDrop() if / elifs + dragDrop()

which makes my scripts slow (I perform hundred of iterations everyday) 这使我的脚本变慢 (我每天执行数百次迭代)

Is there a way I can find (a1) (because its always present after clicking (3)) , save its coordinates and use it as a param for scrolldown_codes like this 有没有办法可以找到(a1) (因为它总是在点击(3)后出现) ,保存它的坐标并将其用作scrollldown_codes的参数,如下所示

   #after clicking drop-down
   #find and get (action1) coordinates
   def scroll_down(coordinates):              #pass it here
       while not exist(action(n).png):        #n = action choice 
          end_Y = coordinates
          start_Y = coodinates - few_Y
          dragdrop(start_Y, end_Y)
          wait(1)
       click(action(n).png)

Please help me! 请帮我! Feel free to suggest anything helpful! 随意提出任何有用的建议!

Note: Im only allowed to click and drag while on that GUI because its a touchscreen product we're developing. 注意:我只允许在该GUI上单击并拖动,因为它是我们正在开发的触摸屏产品。

Actual scrolling, as you would do with the scrollbar, is probably not the best solution as it requires many additional actions that all prone to failure due to various reasons. 与滚动条一样,实际滚动可能不是最佳解决方案,因为它需要许多因各种原因而容易出现故障的其他操作。 What I usually suggest in such cases is using keyboard to control the selection. 在这种情况下我通常建议使用键盘来控制选择。 There are few options really and that depends on how your application behaves. 实际上很少有选项,这取决于您的应用程序的行为方式。 So I will list few tricks that might be used in your scenario and you decide what suits you best. 因此,我将列出可能在您的方案中使用的一些技巧,并确定最适合您的方法。

First of all, keep in mind that you can speed up the search time by limiting the area you are looking in. There are many ways to do that. 首先,请记住,您可以通过限制您正在查看的区域来加快搜索时间。有很多方法可以做到这一点。 For example: 例如:

  1. Split the screen if you know that the patters you are looking for are expected to appear only in certain area. 如果您知道您要查找的图案预计仅出现在某个区域,请拆分屏幕

  2. Relative search / Region extension . 相对搜索/区域扩展 You can find the relevant (3) item and then expand the region to its right to capture the area where the (4) selector (3 dots) is located. 您可以找到相关的(3)项目,然后展开其右侧的区域以捕获(4)选择器(3个点)所在的区域。 This will speed up the search significantly as it will only look in a small area rather than the whole screen and it will ensure you are clicking the correct (4) item. 这将显着加快搜索速度,因为它只会在一个小区域而不是整个屏幕中查看,它将确保您单击正确的(4)项目。 More info and examples about region expansion here . 更多信息和有关区域扩张的例子在这里 More info on optimizing search time here . 优化搜索时间更多信息在这里

Now to the actual item selection in a menu. 现在到菜单中的实际项目选择。 So, as I mentioned, I reckon you better off using your keyboard to select the item. 因此,正如我所提到的,我认为最好使用键盘来选择项目。 That means selecting/clicking on the first item in the list and then pressing the down arrow button x times until you reach the menu item you are after. 这意味着选择/单击列表中的第一项,然后按向下箭头按钮x次,直到到达您所在的菜单项。 There are few ways to hit the down arrow button correct number of times: 有几种方法可以按下向下箭头按钮正确的次数:

  1. Hard code it. 硬编码吧。 If you know that the specific item is fourth in list just click 4 times. 如果您知道特定项目在列表中排名第四,则单击4次。

  2. Press arrow down button until you reach the desired item. 按向下箭头按钮,直到您到达所需的项目。 That might be a bit slower and might require taking additional screenshots but might prove useful if you do not know what order the items are in or if that is prone to change. 这可能会有点慢,可能需要拍摄额外的屏幕截图,但如果你不知道这些项目的顺序或者是否容易发生变化,可能会有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM