2

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

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

有没有办法做到这一点?

4

3 回答 3

3

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

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
于 2015-09-22T22:00:31.397 回答
1

执行此类任务的一种非常有效的方法是使用 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。

于 2016-08-19T20:57:02.563 回答
0

我们不能使用这个简单提到的代码来验证 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将验证数据是否存在,在下一步中,它将使用 click 突出显示该数据FoundImageLocation()

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

于 2019-12-17T19:00:31.513 回答