class AmazonHomePageLocator: # Use the following description for different locators # CSS - 'css selector' # XPATH - 'xpath' # ID - 'id' # NAME - 'name' # LINK TEXT - 'link text' # PARTIAL LINK TEXT - 'partial link text' # TAG NAME - 'tag name' # CLASS NAME - 'class name' amazon_logo = Locator("css selector", "div#nav-logo a[aria-label='Amazon']") # In chrome amazon_search_categories works fine for select # In firefox we have an open issue with the amazon_search_categories = Locator( "css selector", "div.nav-search-scope select.nav-search-dropdown") amazon_search_categories_text = Locator("css selector", "div.nav-search-facade span") amazon_search_textbox = Locator("css selector", "div.nav-search-field input.nav-input") amazon_search_button = Locator("css selector", "div.nav-search-submit") def __init__(self): print("Locators for Amazon home page") # Dynamic locators can be declared as a method with variables. @staticmethod def amazon_search_category_list(string): amazon_search_category_list = Locator( "xpath", "//select[contains(@class,'nav-search-dropdown')]//option[text(" ")='%s']" % string) return amazon_search_category_list
class AmazonSearchResultLocator: # Use the following description for different locators # CSS - 'css selector' # XPATH - 'xpath' # ID - 'id' # NAME - 'name' # LINK TEXT - 'link text' # PARTIAL LINK TEXT - 'partial link text' # TAG NAME - 'tag name' # CLASS NAME - 'class name' amazon_search_result_top_header = Locator("css selector", "div.sg-col-inner div.a-section") amazon_search_result_department_see_more = Locator("css selector", "div#departments span.a-expander-prompt") amazon_search_sort_by = Locator("css selector", "span.a-dropdown-container") amazon_search_price_min = Locator("css selector", "div#priceRefinements input[placeholder='Min']") amazon_search_price_max = Locator("css selector", "div#priceRefinements input[placeholder='Max']") amazon_search_price_go = Locator("css selector", "div#priceRefinements span.a-button") def __init__(self): print("Locators for Amazon search result page page") @classmethod def amazon_search_result_department(cls, string): return Locator("xpath", "//div[@id='departments']//li[contains(@class,'a-spacing-micro')]" "//span[text()='%s']" % string) # For average customer review use the following strings for respective avg cust review # 4 Stars & Up # 3 Stars & Up # 2 Stars & Up # 1 Star & Up @classmethod def amazon_search_avg_customer_review(cls, string): return Locator("css selector", "div#reviewsRefinements section[aria-label='%s']" % string) @classmethod def amazon_search_sort_by_selector(cls, string): return Locator("xpath", "//div[contains(@class,'a-popover-inner')]//a[text()='%s']" % string) @classmethod def amazon_search_checkbox_filters(cls, string): return Locator("xpath", "//ul[contains(@class,'a-unordered-list')]//span[text()='%s']" % string) @classmethod def amazon_search_result_list_header(cls, number): return Locator("xpath", "((//div[contains(@class,'s-result-list')]//div" "[contains(@class,'s-include-content-margin')])[%s]//div" "[contains(@class,'sg-col-4-of-12')]//div[@class='sg-row']//span)[1]" % number)
class AmazonProductPageLocator: # Use the following description for different locators # CSS - 'css selector' # XPATH - 'xpath' # ID - 'id' # NAME - 'name' # LINK TEXT - 'link text' # PARTIAL LINK TEXT - 'partial link text' # TAG NAME - 'tag name' # CLASS NAME - 'class name' amazon_deliver_to_link = Locator("css selector", "div#contextualIngressPt") amazon_deliver_to_pincode = Locator( "css selector", "div.a-column input[aria-label='or enter a pincode']") amazon_deliver_to_pincode_apply = Locator( "css selector", "div.a-column input.a-button-input") amazon_product_page_identifier = Locator("css selector", "div#dp") # Product details locator amazon_popup_close = Locator( "css selector", "div.a-popover-wrapper span.a-button-inner input.a-button-input") amazon_product_img = Locator("css selector", "div#leftCol img") amazon_product_title = Locator("css selector", "span#productTitle") amazon_product_byline_info = Locator("css selector", "div#bylineInfo") amazon_product_show_more_format = Locator("css selector", "span#showMoreFormatsPrompt") amazon_product_formats = Locator("css selector", "div#formats") amazon_product_detail_description_iframe = Locator( "css selector", "iframe#bookDesc_iframe") amazon_product_detail_description = Locator("css selector", "div#iframeContent") amazon_product_description = Locator( "css selector", "div#productDescription_feature_div.a-row") amazon_product_offers = Locator("css selector", "div#sopp_feature_div") amazon_product_details = Locator("css selector", "div#detail_bullets_id") def __init__(self): print("Amazon Product page locator")
def amazon_search_result_list_header(cls, number): return Locator("xpath", "((//div[contains(@class,'s-result-list')]//div" "[contains(@class,'s-include-content-margin')])[%s]//div" "[contains(@class,'sg-col-4-of-12')]//div[@class='sg-row']//span)[1]" % number)
def amazon_search_checkbox_filters(cls, string): return Locator("xpath", "//ul[contains(@class,'a-unordered-list')]//span[text()='%s']" % string)
def amazon_search_sort_by_selector(cls, string): return Locator("xpath", "//div[contains(@class,'a-popover-inner')]//a[text()='%s']" % string)
def amazon_search_avg_customer_review(cls, string): return Locator("css selector", "div#reviewsRefinements section[aria-label='%s']" % string)
def amazon_search_result_department(cls, string): return Locator("xpath", "//div[@id='departments']//li[contains(@class,'a-spacing-micro')]" "//span[text()='%s']" % string)
def amazon_search_category_list(string): amazon_search_category_list = Locator( "xpath", "//select[contains(@class,'nav-search-dropdown')]//option[text(" ")='%s']" % string) return amazon_search_category_list