class ProductEntry: def __init__(self, product_entry): self.a_link = Find(by=By.CSS_SELECTOR, value="a.s-access-detail-page", context=product_entry) self.name = Find(by=By.CSS_SELECTOR, value="h2.s-access-title", context=product_entry).get_attribute('data-attribute') self.dash_name = '-'.join(self.name.split(' ')) self.url = self.a_link.get_attribute('href') def get_asin(self): return urlparse(self.url).path.split('/')[3] def get_unquoted_product_part(self): return unquote(urlparse(self.url).path.split('/')[1]) @allure.step def check_url(self): logging.info(self.dash_name + '\n' + self.get_unquoted_product_part()) return self.dash_name.startswith(self.get_unquoted_product_part()) @allure.step def check_asin(self): asin = self.get_asin() logging.info(asin + ' ' + self.url) return len(asin) == 10 and set(asin).issubset( set("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")) @allure.step def open_details_page(self): self.a_link.click() return DetailsPage(self.get_asin())
def get_filtered_data(self, table_name, column): self.replace_bad_elements() column_name = self.row_names_selects_map.get(column, column) column = Find( by=By.XPATH, value='//span[contains(., "{}")]/../..//div[.="{}"]/parent::th'.format(table_name, column_name), context=self ) column_id = column.get_attribute('id') rows = Finds(by=By.CSS_SELECTOR, value='td[aria-describedby="{}"]'.format(column_id), context=self) rows_text = [r.text for r in rows] return set(filter(lambda x: x.strip() and 'Clients' not in x, rows_text))
def add_package(self, package_name): package = Find(by=By.XPATH, value='//td[contains(., "{}")]/a'.format(package_name), context=self) package.click() return package.get_attribute('data-id')