# Generated by Selenium IDE
import time
from selenium import webdriver
from selenium.webdriver.common.by import By


class TestTest3():
    def setup_method(self, method):
        self.driver = webdriver.Chrome()
        self.vars = {}

    def wait_for_window(self, timeout=20):
        time.sleep(round(timeout / 1000))
        wh_now = self.driver.window_handles
        wh_then = self.vars["window_handles"]
        if len(wh_now) > len(wh_then):
            return set(wh_now).difference(set(wh_then)).pop()

    def test_test3(self):
        # open home page
        self.open_home_page()
        # searching
        self.searching()
        # redirect to item page
        time.sleep(10)
        self.vars["window_handles"] = self.driver.window_handles
        self.driver.find_element(By.CSS_SELECTOR, ".x-gallery-tile:nth-child(2) .x-image-holder__img").click()
        self.vars["win7443"] = self.wait_for_window(2000)
        self.driver.switch_to.window(self.vars["win7443"])
        self.driver.execute_script("window.scrollTo(0,0)")

    def searching(self):
        self.driver.find_element(By.NAME, "search_term").click()
        self.driver.find_element(By.NAME, "search_term").send_keys("крісло карпове")
        time.sleep(10)
        self.driver.find_element(By.CSS_SELECTOR, ".ps-search__buttonIcon--2FLNY").click()

    def open_home_page(self):
        self.driver.get("https://prom.ua/")
        self.driver.set_window_size(1258, 614)

    def teardown_method(self, method):
        self.driver.quit()
