def click_filter(self, name, value, expand=True): div = self.driver.find_element_by_xpath(''.join([ '//*[@name="' + name + '"]', '/ancestor::fieldset', '/parent::div[contains(@class, "filter")]', ])) checkbox = div.find_element_by_css_selector( 'input[type="checkbox"][value="' + value + '"]' ) label = checkbox.find_element_by_xpath('following-sibling::label') # Ensure performance bar doesn't block clicks self.driver.execute_script('$(".perfBar-bar").hide()') if expand: try: button = div.find_element_by_css_selector('button.dropdown__button') except NoSuchElementException: button = None if button: utils.try_until(lambda: button.click()) # Handle probabilistic checkbox click failures in Chrome checked = bool(checkbox.get_attribute('checked')) utils.try_until( lambda: label.click(), condition=lambda: bool(checkbox.get_attribute('checked')) != checked, )
def check_sort(driver, index, parser, reverse=False): table = driver.find_element_by_css_selector('table#results') get_values = lambda: [ parser(row.find_elements_by_tag_name('td')[index].text) for row in table.find_elements_by_css_selector('tr[role="row"]')[1:] ] values = utils.try_until(get_values, errors=(StaleElementReferenceException, )) assert values == sorted(values, reverse=reverse)
def check_filter_results(self, index, result): utils.wait_for_event(self.driver, 'draw.dt', 'draw', timeout=0.5) # Handle stale reference errors in Chrome get_values = lambda: [ row.find_elements_by_tag_name('td')[index].text for row in self.driver.find_elements_by_css_selector('tbody tr[role="row"]') ] values = utils.try_until(get_values, errors=(StaleElementReferenceException, )) if callable(result): for value in values: self.assertTrue(result(value)) else: result = set([result]) if not isinstance(result, set) else result self.assertTrue(result.issuperset(values))
def toggle_sort(driver, index): table = driver.find_element_by_css_selector('table#results') column = table.find_elements_by_tag_name('th')[index] utils.try_until(lambda: column.click()) utils.wait_for_event(driver, 'draw.dt', 'draw', timeout=0.5)