【问题标题】:Sikuli gets confused between 2 identical buttonsSikuli 对 2 个相同的按钮感到困惑
【发布时间】:2013-11-20 22:37:40
【问题描述】:

我在同一页面上有相同的按钮,我希望 Sikuli 只单击其中一个,但最终会单击另一个名称的缘故按钮。不幸的是,按钮名称无法更改。关于如何处理这种情况的任何建议?

谢谢!

【问题讨论】:

    标签: button click sikuli


    【解决方案1】:

    您可以告诉 Sikuli 在屏幕上相对于给定图像/屏幕截图对象的特定区域进行操作。这称为 TargetOffset。参考here 假设您正在询问以编程方式使用 sikuli。在 Sikuli IDE 中,双击截图图像,它会弹出一个窗口,您可以在其中设置准确度和 targetOffset。

    【讨论】:

      【解决方案2】:

      如果两个图标靠得很近,并且总是以相同的方式出现,并且它们之间的间距总是相同,那么一个

      click(imageOfTwoIcons).targetOffset(x,y)
      

      可能是最简单的方法。但是,如果有什么东西会使这个方法变得不可靠(两个图标之间的任何东西都与你截屏时不同)--

      您还可以使用 python sorted() 函数按图像位置对图像进行排序。例如,如果一个图像总是在另一个之上,那么您可以找到两个图像并按它们的 y 坐标对它们进行排序,如下所示:

      #a little prep for the sorted function to get the y coord of the icon
      def byY(icon):
          return icon.y
      
      #findAll() on your two identical icons and make them into a list
      bothIcons = list([x for x in findAll(icon)]) 
      
      #then sort them
      sortedIcons = sorted(bothIcons, key=byY)
      iconOnTop = sortedIcons[0]  
      iconOnBottom = sortedIcons[1]
      
      #then click on the one you want
      click(iconOnTop) #or save a line and say: click(sortedIcons[0])
      

      如果您知道感兴趣的图标总是在其双胞胎的左侧或右侧,也可以这样做:

      def byX(yourTwoImages):
          return image.x
      bothIcons = list([x for x in findAll(icon)])
      sortedIcons = sorted(bothIcons, key=byX)
      click(sortedIcons[0]) #for the image on the left
      

      如果两个图标在屏幕上靠得很近,或者图标的位置可能会发生变化,我更喜欢使用区域。

      【讨论】:

        【解决方案3】:

        您可以放大按钮图像,以便图像不仅包括图像,还包括其周围的背景(如果您可以确定背景没有改变),但请记住 sikuli 点击的中心图片,所以请确保按钮在中间。

        另一种选择是使用偏移量单击 (http://doc.sikuli.org/tutorials/checkone/checkone.html) 使用这样的东西:

        this.offset = 15;
        org.sikuli.script.Region reg = screen.find("image").left(this.offset);
        screen.click(reg);

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-09-29
          • 1970-01-01
          • 2021-09-05
          • 1970-01-01
          • 2019-09-13
          • 2012-07-22
          相关资源
          最近更新 更多