import time
# from lib2to3.pgen2 import driver
from selenium.webdriver.common.by import By
from Base.BasePage import BasePage



class Create(BasePage):
    def __init__(self):
        super().__init__('web')
        # 点击创建书刊
        self.reader_book = (By.XPATH, '/html/body/div[1]/div/section/div[1]/div[2]/div/div/div/div[1]/div[3]/div/div['
                                      '2]/div/div/div/div/div/div[1]/button/span')
        self.reader_book1 = (By.XPATH, "/html/body/div[1]/div/section/div[1]/div[2]/div/div[2]/div/form/div["
                                       "1]/div/div[2]/div/div/div")
        # 书刊分类-教辅
        self.reader_book2 = (By.XPATH, "//ul[1]//li[1]//div[2]//i[1]")
        # 书刊分类-K12同步教材教辅
        self.reader_book3 = (By.XPATH, "//ul[2]//li[1]//div[2]//i[1]")
        # 书刊分类-同步教案
        self.reader_book4 = (By.XPATH, "//ul[3]//li[3]//div[1]")
        # 书刊标签-三年级
        self.reader_graLabelId = (By.ID, "graLabelId")
        self.reader_book6 = (By.XPATH, "/html/body/div[3]/div/div/div/div[2]/div[1]/div/div/div[5]/div")
        # 书刊标签-数学
        self.reader_subLabelId = (By.ID, "subLabelId")
        self.reader_book7 = (By.XPATH, "/html[1]/body[1]/div[4]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div["
                                       "2]/div[1]")
        # 书刊标签-人教版
        self.reader_verLabelId = (By.ID, "verLabelId")
        self.reader_book8 = (By.XPATH, "/html/body/div[5]/div/div/div/div[2]/div[1]/div/div/div[1]")
        # 书刊标签-全一册
        self.reader_volLabelId = (By.ID, "volLabelId")
        self.reader_book9 = (By.XPATH, "/html[1]/body[1]/div[6]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div["
                                       "1]/div[1]")
        # 书刊条形码-其它
        self.reader_other = (By.XPATH, "/html/body/div[1]/div/section/div[1]/div[2]/div/div[2]/div/form/div["
                                       "3]/div/div[2]/div/div/span/div[1]/div/div/div/div/div/label[4]")
        # 输入isbn
        self.reader_isbn = (By.ID, "isbn")
        #
        self.reader_button = (By.XPATH, "/html/body/div[1]/div/section/div[1]/div[2]/div/div[2]/div/form/div["
                                        "4]/div/div/div/div/button")
        # 书刊名称
        self.reader_name = (By.ID, "autoTextarea")
        #书刊封面
        self.reader_book0 = (By.XPATH, "//div[@class='image-list-wrapper']//div[2]//button[1]//span[1]")
        # 保存
        self.reader_primary = (By.XPATH, "/html/body/div[1]/div/section/div[1]/div[2]/div/div[2]/div/div/button[2]")

    def create(self):
        self.find_ele(self.reader_book).click()
        time.sleep(1)
        self.find_ele(self.reader_book1).click()
        time.sleep(1)
        self.find_ele(self.reader_book2).click()
        time.sleep(1)
        self.find_ele(self.reader_book3).click()
        time.sleep(1)
        self.find_ele(self.reader_book4).click()
        time.sleep(1)
        self.find_ele(self.reader_graLabelId).click()
        time.sleep(1)
        self.find_ele(self.reader_book6).click()
        time.sleep(1)
        self.find_ele(self.reader_subLabelId).click()
        time.sleep(1)
        self.find_ele(self.reader_book7).click()
        time.sleep(1)
        self.find_ele(self.reader_verLabelId).click()
        time.sleep(1)
        self.find_ele(self.reader_book8).click()
        time.sleep(1)
        self.find_ele(self.reader_volLabelId).click()
        time.sleep(1)
        self.find_ele(self.reader_book9).click()
        time.sleep(1)
        self.find_ele(self.reader_other).click()
        time.sleep(1)
        self.find_ele(self.reader_isbn).send_keys(int(time.time() * 1000))
        time.sleep(1)
        self.find_ele(self.reader_button).click()
        time.sleep(1)
        self.find_ele(self.reader_name).send_keys("UI自动化书刊")
        time.sleep(1)
        self.find_ele(self.reader_book0).click()
        time.sleep(1)
        self.find_ele(self.reader_primary).click()
