Hello Mike,
I'll try to give some hint but I'm not sure of what I say

Mike Taber a écrit :
Right now, I have a user extension that I have created - it works, but really should be cleaned up, and parts of it can be used for other purposes...
 
One part of my functionality simply counts the number of rows (of some "class" - specified by an xpath) in a table.
It looks something like this (far from cleaned up or optimized):
 
var junk = null;
var count = 1; // lets start with 1, since we know we have at least 1 row
var done = 0;  // we are not yet done
while (done != 1) {
    // Look for rows
      try {
           junk = this.page().findElement(locator + "[" + count + "]");
      }
      catch (e) {
           // We did not find an "even" row
           done = 1;
           count = (count - 1); // Take away the last increment, since we did not find one
      }
  
    if (done != 1) {
       count++;
      }
}

Just in case, I think, count(//[EMAIL PROTECTED]"alternatingRowEven\"]) is a valid Xpath _expression_ (but does not return a not set but a value). you could use a modified version of findElementUsingFullXPath (in selenium-browserbot.js) to test this xpath directly.
My locator looks something like this:
"//[EMAIL PROTECTED]"alternatingRowEven\"]"
When all is said and done we are looking for an element with a xpath like this:
"//[EMAIL PROTECTED]"alternatingRowEven\"][1]"
I just change the index value each time thru...
 
So, basically, I'm looking at the table until I don't find any more elements matching.
Then I keep my count to use later on.
 
I need to "do" this for more than just this one "class" - I have a couple different classes of rows (and elements) that I need to count, so I'd like to breakout the row counting into a function I can call from my Selenium user extension - so, my Selenium.prototype.doSomeClickThing would call my function getRowCount.
 
The thing I've not figured out how to do (and I'm sure I'm just blind and can't see the answer) is to "find" the element from inside a function (the line in my user extension would look something like this: var someCount = getRowCount("//[EMAIL PROTECTED]"alternatingRowEven\"]");
 
So, how would I replace this line (from above) in my getRowCount function called by my Selenium doSomeClickThing command:
junk = this.page().findElement(locator + "[" + count + "]");
Hope this makes sense and thanks in advance for any hints you all may have.
Do you really have to change it ? 'this' refers to the object, so if getRowCount is a function of Selenium (you defined Selenium.prototype.getRowCount() =....), 'this.page' returns you the current document and it should roll right !

Alex.





_______________________________________________
Selenium-users mailing list
Selenium-users@lists.public.thoughtworks.org
http://lists.public.thoughtworks.org/mailman/listinfo/selenium-users

Reply via email to