Exception Handling

I have 10 libraries in my folder(SUT machine). These library names are placed in to one .csv file .in our machine
Now I am taking the libraries one by one (Here I am taking each and every library is one variable like temp1)

  1. If library (abc) is found it should click the text and continue the script on SUT machine
  2. If second library(bcd- attached .csv file) is not found it should check the screen,then it should go and pick the third library and continue the script.

My requirement is if library name is not found in the SUT machine, it should go and take the third library name and continue the script.Should not stop any where .


Set filePath="Filepath\libraryFramework.csv" 
Log "File path is =", filePath 
(*Read the library name from library .csv file*) 
if file filePath exists then	
Repeat with lineno= EACH LINE OF File filePath 
(* A library is found with execution flag true *) 
if item 2 of lineno ="YES" then 
put item 1 of lineno into textToBeFound 
Log "Library name to be found =", textToBeFound	
put textToBeFound into temp1 
ImportingLibary --This function is for select libraries folder 
(*Select the library name from .csv file*) 
Put ReadText ("TLImage","BRImage") into TextFound -- read text within the SearchRectangle (no need to specify SearchRectangle as a parameter for ReadText when it is the only parameter). 
replace every occurrence of return in TextFound with comma -- replace the return characters with commas 
Log TextFound -- log the results 
if Imagefound (Text:temp1 ,SearchRectangle: ("TLImage","BRImage"),ignorespaces:true) 
Click foundImageLocation () 
else 
Repeat while not ImageFound (Text:temp1,SearchRectangle: ("TLImage","BRImage"),ignorespaces:on) 

if Imagefound (Text:temp1 ,SearchRectangle: ("TLImage","BRImage"),ignorespaces:on) 
else if imagefound ("BottomScroll") 
LogError "Library-" && temp1 && "is not available" 
Exit Repeat 
else 
if Imagefound ("Scrollbar") 
DoubleClick "Scrollbar" 
moveto MouseLocation()+(15,0) 
else 
end if 
end if 
end Repeat 
Click foundImageLocation () 
end if 
else 
end if 
end Repeat 
end if 

Your code seemed like it should work, but it was a little inefficient. I’ve attempted to clean it up a bit:

Set filePath="Filepath\libraryFramework.csv"
Log "File path is =", filePath
(*Read the library name from library .csv file*)
if file filePath exists then   
	Repeat with lineno= EACH LINE OF File filePath
		(* A library is found with execution flag true *)
		if item 2 of lineno ="YES" then
			put item 1 of lineno into textToBeFound
			Log "Library name to be found =", textToBeFound   
			ImportingLibary --This function is for select libraries folder
			(*Select the library name from .csv file*)
			Put ReadText ("TLImage","BRImage") into TextFound -- read text within the SearchRectangle (no need to specify SearchRectangle as a parameter for ReadText when it is the only parameter).
			replace every occurrence of return in TextFound with comma -- replace the return characters with commas
			Log TextFound -- log the results
			set Found to YES
			Repeat while not ImageFound (Text:textToBeFound,SearchRectangle: ("TLImage","BRImage"),ignorespaces:on)				
				if imagefound ("BottomScroll") or if not imageFound("scrollbar")
					LogError "Library-" && textToBeFound && "is not available"
					set Found to NO
					Exit Repeat
				else
					DoubleClick "Scrollbar"
					moveto MouseLocation()+(15,0)
				end if
			end Repeat
			if Found then Click foundImageLocation ()
		end if
	end Repeat
end if 

A few notes:
[list]
[]There didn’t seem to be any reason to assign TextToBeFound to Temp1. It just seemed like an extra step. Temp1 was never modified, so it’s not as though you were preserving the value of TextToBeFound. So I removed that step and just used the more descriptive TextToBeFound throughout.
[
]You checked for the existence of the text and then moved on to a repeat loop, the condition of which was whether the text existed. So your initial if/else was unnecessary – the loop condition handles it.
[]I’m not sure why you’re double-clicking on a scrollbar – does that “grab” it so the the move scrolls things?
[
]The condition under which you decide that the text isn’t there should include there not being any scroll bar – no scroll bar, nowhere to scroll, no possibility of finding the item. So I added that check to the “if imagefound(bottomscroll)” conditional and removed it in the else.
[]Regardless of the outcome of the repeatloop, you were clicking “foundImageLocation()”. If the thing wasn’t found, there would be no reason to do this, so I added a boolean variable that gets set to NO when the repeat loop fails to find the item, and the click only occurs if it is set to YES.
[
]Your scroll is scrolling across the screen from left to right. Did you mean to do that, or should it be scrolling up and down, in which case your code should be: Moveto mouseLocation() + (0, 15) // increments the y value
[*]Finally, I’m not sure what the purpose of the whole first part with the ReadText() is. Unless you need to click on the dll, you could verify that it’s listed by saying:

			if TextFound contains TextToBeFound then logSuccess "Found the dll!"

Of course, as your code is written, that would only work if the dll was found in the first screenful of text – you’d need to move this code into the repeat loop to do it by text comparison as you scrolled.
[/list:u]