【问题标题】:Eggplant/Sensetalk Search for string then grab the next wordEggplant/Sensetalk 搜索字符串然后抓取下一个单词
【发布时间】:2015-10-27 11:51:23
【问题描述】:

我正在学习茄子。我想为特定字符串创建一些字符串,然后抓取该字符串后面的文本。例如,我想获取以下字符串的版本号,因为它发生了变化。

This is some log statement telling me the that the version=1.2.3

有没有办法做到这一点?

【问题讨论】:

    标签: eggplant


    【解决方案1】:

    您可以使用以下代码从该文本行中提取版本号。

    set line = "This is some log statement telling me the that the version=1.2.3"
    set versionIndicator = "version="
    
    if versionIndicator is in line
        set indicatorPosition = word number containing versionIndicator within line
        set versionNumber = word indicatorPosition of text 
        delete versionIndicator from versionNumber --removes "version="
    end if
    

    如果您知道这将是行中的最后一个单词,您可以直接解决它,而不是先计算它的位置。

    if version indicator is in line
        set versionNumber = last word of line
        delete versionIndicator from versionNumber
    end if
    

    【讨论】:

      【解决方案2】:

      执行此类任务的一种非常有效的方法是使用 OCR 搜索的 FoundImageRectangle 属性来创建 SearchRectangle。

      Put ImageRectangle (text:"version=", ValidWords:"*") into VersionTag //Since the string we're searching for isn't a dictionary word the ValidWords:"*" can help out.
      
      Put ReadText ((right of VersionTag, top of VersionTag +5, x of RemoteScreenSize(), bottom of VersionTag), ValidCharacters:"1234567890.") into VersionNumber //Limiting the available characters for the read should improve reliability of the result.
      

      这最终会让你得到字符串“version=”右边的所有文本。如果您可以使用其他一些限制,例如 UI 元素的边缘,则可以使用其中的 X 来代替 RemoteScreenSize。

      【讨论】:

        【解决方案3】:

        我们不能使用这个简单提到的代码来验证 UI 中存在的任何数据吗

        //SearchRectangle concept 
        
        set DATA to "ABCCordinates"
        
        **Put ImageRectangle("ImageLocation")into SR_Searchdropdown
        Set SR_Diff_SearchOption to ((0,0,0,0))
        If ImageFound(text:DATA,SearchRectangle:SR_Searchdropdown+SR_Diff_SearchOption, waitFor:100) then
            Click FoundImageLocation()**
        

        代码说明

        1. 在第一步中,我已经设置了要传递参数的变量。

        2. 使用 step2 我已经放置了基础图像位置

          我已经使用 Log ReadText(0,0,0,0) 计算了基础坐标和目标图像位置坐标,然后我从基础坐标和目标坐标中减去了我得到尊重的坐标我已经粘贴了查找数据的 3 个步骤。

        3. 使用 if ImageFound 的步骤将验证数据是否存在,在下一步中,它将使用点击 FoundImageLocation() 突出显示该数据。

        我认为这是使用搜索矩形坐标查找数据的最简单方法。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2021-11-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-10-22
          • 1970-01-01
          相关资源
          最近更新 更多