crazigrl
crazigrl

Reputation: 21

Eggplant/Sensetalk Search for string then grab the next word

I'm learning Eggplant. I would like to some string for a specific string and then grab the text following that string. For example, I want to get the version number for the following string since it changes.

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

Is there a way to do that?

Upvotes: 2

Views: 1977

Answers (4)

akhilesh mvn
akhilesh mvn

Reputation: 1

Easiest way of doing this would be by using split in my opinion.

set logText = "elling me the that the version=1.2.3"
put logText split by "=" into lst
put item 2 of lst into Version
Log Version

Explanation: Line 2 splits the text with "=" delimiter thus creating a list with 2 items. Whatever is on the left hand side of = goes into item 1 and the right hand part goes into item 2 Item 2 is now our version

Upvotes: 0

Rsujot Tumbde
Rsujot Tumbde

Reputation: 1

Can't we use this simple mentioned code for validating any data present in UI Using

//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()**

Explanation of Code

  1. In the first step, I have set the variable to pass the parameter.

  2. Using step2 I have placed the base image location

    I have calculated the base coordinates and target Image location coordinates using Log ReadText(0,0,0,0), and then I have subtracted from the base and target coordinates I got respected coordinate which I have paste in the 3 steps for finding out the Data.

  3. Step using if ImageFound will validate that the data is present and in the next step, it will highlight that data using click FoundImageLocation().

I think this can be the easiest way to find the data using the Search Rectangle coordinates.

Upvotes: 0

Warren.
Warren.

Reputation: 41

A pretty effective way of doing this kind of task is to use the FoundImageRectangle property of an OCR search to create a 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.

That will end up getting you all the text to the right of the string "version=". If there's some other limit you could use, like the edge of a UI element, then the X of that could be used instead of the RemoteScreenSize.

Upvotes: 1

sphennings
sphennings

Reputation: 1083

You could extract the version number from that line of text using the following code.

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 you know it will be the last word on the line you can address it directly instead of calculating it's position first.

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

Upvotes: 3

Related Questions