Count the number of items on the page



  • I'm starting to deal with autotesting using python + selenium, and all the time I'm tightly stuck in javascript, which I've never dealt with. I need to count unread pages in a large table with all applications. What they have in common is that they have an "unviewed" class. I tried this, but it returns 0.

    def look_for_element (self):
        driver = self.driver
        b []
    try:
        driver.find_element_by_class_name ("unviewed")
        while driver.find_element_by_class_name ("unviewed") == True:
            b.append (driver.find_elements_by_class_name ("unviewed"))
        print (len (b))
    except NoSuchElementException:
        print ('0')
        continue
    

    Before that, I tried in a brazenly very simple:

    def look_for_element (self):
        driver = self.driver
        b []
        b.append (driver.find_elements_by_class_name ("unviewed"))
        print (len (b))
    

    Similarly, I tried to count all the pages in general to check that it was not the wrong path. And it works on all pages in the same way. Item code of any order:

    <tr class = "data-row rowkey-157e2c09fd6a096b061c2baf0b1d8899 unviewed scoring_status_- odd collapsed" data-rowkey = "157e2c09fd6a096b061c2baf0b1d8899">
    


  • This is while driver.find_element_by_class_name ("unviewed") == True: always False.

    I shoul do it just like this:

    def look_for_element (self):
         driver = self.driver
         print len (driver.find_elements_by_class_name ("unviewed")))
    Or better by xpath:
    
    def look_for_element (self):
         driver = self.driver
         print len (driver.find_elements_by_xpath ("// tr [contains (@class, 'unviewed') and @ data-rowkey]")))
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2