Пример #1
0
    def add_products_to_compare(self):
        products_xpath = "//ul[@class='product_list grid row']/li"
        try:
            driver_wait(self.driver, self.clickable_timeout).until(
                EC.presence_of_element_located((By.XPATH, products_xpath)))
            products = self.driver.find_elements_by_xpath(products_xpath)
        except NoSuchElementException:
            raise AssertionError(f"No products in 'Dresses'.")

        for pid, product in enumerate(products):
            add_to_compare_button_xpath = f"{products_xpath}[{pid + 1}]/div[@class='product-container']/div[@class='functional-buttons clearfix']/div[@class='compare']/a[1]"
            self.add_to_compare(product, add_to_compare_button_xpath)
            try:
                overlay_cross_xpath = "//div[@class='fancybox-overlay fancybox-overlay-fixed']/div[@class='fancybox-wrap fancybox-desktop fancybox-type-html fancybox-opened']/div[@class='fancybox-skin']/a[@title='Close']"
                self.check_compare_overlay(pid, overlay_cross_xpath)
                break
            except TimeoutException:
                product_img_src = self.driver.find_element_by_xpath(
                    f"{products_xpath}[{pid + 1}]/div/div[1]/div/a[@class='product_img_link']/img"
                ).get_attribute('src')
                product_name = self.driver.find_element_by_xpath(
                    f"{products_xpath}[{pid + 1}]/div/div[2]/h5/a"
                ).get_attribute('title')
                self.product_properties.append({
                    'img_src': product_img_src,
                    'name': product_name
                })
                continue
            except:
                raise AssertionError(
                    "Something went wrong in overlay calling.")
Пример #2
0
def wait_n_click(self, xpath, wait=True, click=True):
    if wait:
        driver_wait(self.driver, self.clickable_timeout).until(
            EC.element_to_be_clickable((By.XPATH, xpath)))
    obj = self.driver.find_element_by_xpath(xpath)
    if click:
        try:
            obj.click()
        except NoSuchElementException:
            raise NoSuchElementException(
                f"Object with XPATH={xpath} not found.")
        except:
            raise RuntimeError("Something went wrong.")
 def capture_report_screeen(driver):
     screenshot_name = os.getcwd() + "/temp_dashboard.jpg"
     try:
         expected_xpath = """//div[contains(text(),"Can't access report")]"""
         driver_wait(driver,
                     20).until(EC.presence_of_element_located(
                         (By.XPATH, expected_xpath)),
                               message="Can't access report - timeout")
         driver.save_screenshot(screenshot_name)
         return screenshot_name, False
     except Exception as e:
         if "datastudio.google.com" in driver.current_url:
             time.sleep(5)
             driver.save_screenshot(screenshot_name)
             return screenshot_name, True
Пример #4
0
def scrape_locations():
    e_store_summary = driver_wait(page, 2).until(
            conditions.presence_of_element_located(
                (identifier.ID, 'store-summary-accord-id')))
    e_view_more = page.find_element_by_class_name('view-more-stores')
    e_view_more.click()
    e_stores = e_store_summary.find_elements_by_class_name('store-location')

    for each in e_stores:
        print(each.text[0])
Пример #5
0
def wait(driver, timeout, condition):#######
    driver_wait(driver, timeout).until(condition)