def __getitem__(self, item): if isinstance(item, six.string_types): if self.assoc_column is None: raise TypeError('You cannot use string indices when no assoc_column specified!') try: row = self.row((self.assoc_column, item)) except RowNotFound: raise KeyError( 'Row {!r} not found in table by associative column {!r}'.format( item, self.assoc_column)) at_index = row.index elif isinstance(item, int): at_index = item if at_index > self.row_count: raise IndexError('Integer row index {} is greater than row count {}' .format(at_index, self.row_count)) else: raise TypeError('Table [] accepts only strings or integers.') if at_index < 0: # To mimic the list handling at_index = self._process_negative_index(at_index) if self.table_tree: nodes = self.resolver.glob(self.table_tree, '/table/tbody/tr*') at_index = at_index + 1 if self._is_header_in_body else at_index try: return six.next(n.obj for n in nodes if n.position == at_index) except StopIteration: raise RowNotFound('Row not found by index {} via {}'.format(at_index, item)) else: return self.Row(self, at_index, logger=create_item_logger(self.logger, item))
def __getitem__(self, item): if isinstance(item, six.string_types): index = self.table.header_index_mapping[self.table.ensure_normal( item)] elif isinstance(item, int): index = item else: raise TypeError("row[] accepts only integers and strings") # We need to do adjustments if a <th> tag exists inside the row... # Typically the layout is: <td>, <th>, <td>, <td>, <td>, and so on... if self.has_row_header: if index == 1: # We assume the header entry always sits at position 1. Return a TableColumn for it. # Pass position '0' since the Column __locator__ uses 'position + 1' return self.TABLE_COLUMN_CLS(self, 0, logger=create_item_logger( self.logger, item)) if index > 1: # Adjust the index for td objects that exist beyond the th so xpath is valid index = index - 1 # After adjusting the index, call the original __getitem__ to get our TableColumn item return super(PatternflyTableRow, self).__getitem__(index)
def __getitem__(self, item): if isinstance(item, six.string_types): index = self.table.header_index_mapping[self.table.ensure_normal(item)] elif isinstance(item, int): index = item else: raise TypeError("row[] accepts only integers and strings") return self.Column(self, index, logger=create_item_logger(self.logger, item))
def _all_rows(self): # passing index to TableRow, should not be <1 # +1 offset on end because xpath index vs 0-based range() if self.table_tree: for node in self.resolver.glob(self.table_tree, '/table/tbody/tr*'): yield node.obj else: for row_pos in range(self.row_count): yield self.Row(self, row_pos, logger=create_item_logger(self.logger, row_pos))
def _filter_rows_by_query(self, query): # Preload the rows to prevent stale element exceptions rows = [] for row_element in self.browser.elements(query, parent=self): row_pos = self._get_number_preceeding_rows(row_element) # get_number_preceeding_rows is javascript driven, and does not account for thead # When it counts rows, if the header is in the body of the table, then our index is # incorrect and has to be decreased # If the header is not in the body of the table, number of preceeding rows is 0-based # what is correct rows.append(self.Row(self, row_pos - 1 if self._is_header_in_body else row_pos, logger=create_item_logger(self.logger, row_pos))) return rows
def __getitem__(self, item): if isinstance(item, six.string_types): index = self.table.header_index_mapping[self.table.ensure_normal(item)] elif isinstance(item, int): index = item else: raise TypeError("row[] accepts only integers and strings") # Typically for this widget the layout is: <th>, <td>, <td>, <td>, and so on... if self.has_row_header: return self.Column( self, index, self.table.content_view, logger=create_item_logger(self.logger, item) ) return super(PatternflyTableRow, self).__getitem__(index)
def __getitem__(self, item): if isinstance(item, six.string_types): index = self.table.header_index_mapping[self.table.ensure_normal(item)] elif isinstance(item, int): index = item else: raise TypeError('row[] accepts only integers and strings') if self.table.table_tree: # todo: add support of xpath and/or iteration to anytree lib return self.table.resolver.glob(self.table.table_tree, '/table/tbody/tr[{}]/*[{}]'.format(self.index, index))[0].obj else: return self.Column(self, index, logger=create_item_logger(self.logger, item))