| || |
How to Search Text Faster webtable with 4000 rows, current method getcelldata is slow
Searching for faster method to search a text in a table and get a row number back on a table more than 4000 rows. If text is within first 30 or so speed is ok but if text is some where down the table or middle of the table then it take forever. Currently I am using following method to search.
RowFound = False
for i = 2 to vTableRowCt
Print "Current Row Searching..:"&(i-1)
if Browser("creationtime:=1").Page("title:=.*").WebTa ble("html tag:=TABLE","index:=1","html id:=MobileTable").GetCellData(i, 2) = vTextSearch then
RowFound = True
print "Found the Text with Row#..:"&(iRow -1)
If RowFound = False Then
Print "Search Failed or Car was not found on this Table"
Reporter micFail, "Search for string or RailCar", "Not Found"
In the above offending line, notice all the chaining you're doing. So you are issuing a re-find on each parent element. What you want to do is store the reference to the table inside a single reference outside that loop.
Originally Posted by szkapoo
Also, object acquisition is a very slow activity, if your computers have enough memory, it's better to fetch all the cells into an array and iterate over an array instead of doing a find over each cell.
Yeah, all that regex in a loop is a recipe for a bad time.
Have you used the built in GetRowWithCellText method? That should be the pretty quick.
Couple of other things you could try if you are still having performance issues:
Use a With statement:
Create a Table Class with a find method. At runtime create your table class using your HTML table and use the find method.
With Browser("creationtime:=1").Page("title:=.*").WebTa ble("html tag:=TABLE","index:=1","html id:=MobileTable")
.... Do your search stuff
We have some Java-embedded Firefox pages that QTP does not recognise and we have to expose the DOM using the Java extensibility kit. Loading the tables into an object gives a good performance improvement.
I have found that the best solution for this kind of thing is to retreive the entire table and store it in an array. Then traverse the array and find the values that you desire. It is significantly faster to traverse an array vs making one call to an object every single time!
QTP tutorial for beginners to advanced users. 80+ QTP tutorials.
Yes, I tried GetRowWithCellText method and its faster then getcelldata method but GetRowWithCellText method does not find exact match of a string, and that's the only reason I ended up using getcelldata with a for loop.
Originally Posted by NoUse4aName
I will try "Use a With statement" method and let you know
Originally Posted by mwsrosso
Can you give me a example on how would I go about creating this class, I have not created any class in vb yet.
What do you mean by that? Returns results that are just a substring not an exact match? It unfortunately does not take in regex. But may be able to find a way to wrap your input to only return what you want.
Originally Posted by szkapoo
You can at least use that to reduce the scope of what you check. Setup a loop that uses getrowwithcelltext, on the first hit check the exact cell contents, if that's not it, getrowwithcelltext again with a new StartFromRow parameter. You can also feed it a fixed column optional param to increase performance.