茄子/ Sensetalk搜索字符串然后抓住下一个单词

时间:2015-08-04 21:55:00

标签: eggplant

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

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

有办法吗?

3 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分: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。

答案 2 :(得分: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我放置了基本图像位置 我已经使用计算了基本坐标和目标图像位置坐标 记录ReadText(0,0,0,0) 然后我从基本坐标和目标坐标中减去了我所尊重的坐标,我将其粘贴到3个步骤中以找出数据。 第4步使用ImageFound将验证数据是否存在,并在下一步中使用Click FoundImageLocation()突出显示该数据。

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

相关问题