import time


from selenium.webdriver.common.by import By

from Base.BasePage import BasePage
from common.cutils import get_text
from common.untils import DriverTools
from config import user_name, password
from paga.CodePage import Code
from paga.CreatePage import Create
from paga.LoginPage import Login
from paga.GivePage import Give


class Del(BasePage):
    def __init__(self):
        super().__init__('web')
        # 点击书刊管理按钮
        self.reader_return = (By.XPATH, "/html/body/div[1]/div/div/div[2]/ul/li[2]/ul/li[2]")
        # 定位书刊搜索
        self.reader_content = (By.ID, "name")
        # 点击查询按钮
        self.reader_query = (By.XPATH, "//div[@class='btn-item']//button[@class='ant-btn ant-btn-primary "
                                       "ant-btn-background-ghost']//span")
        # 点击更多按钮
        self.reader_more = (By.XPATH, "//div[@class='book-item-list']//div[1]//div[3]//div[1]//span[1]//label["
                                      "1]//button[1]//span[1]")
        # 点击删除
        self.reader_delete = (By.XPATH, "//div[@class='book-item-list']//div[1]//div[3]//div[1]//span[1]//ul[1]//li["
                                        "4]//div[1]")
        # 二次确认
        self.reader_confirm = (By.XPATH, "//button[@class='ant-btn ant-btn-primary']//span")
        # 鼠标悬浮删除成功
        self.person_name = (By.XPATH, "//span[@class='title-text']")

    def delete(self):
        self.find_ele(self.reader_return).click()
        time.sleep(1)
        self.find_ele(self.reader_content).send_keys("红楼梦")
        time.sleep(1)
        self.find_ele(self.reader_query).click()
        time.sleep(1)
        self.find_ele(self.reader_more).click()
        time.sleep(1)
        self.find_ele(self.reader_delete).click()
        time.sleep(1)
        self.find_ele(self.reader_confirm).click()
        time.sleep(1)
        get_text(self.person_name)


if __name__ == '__main__':
    DriverTools.get_driver().get('https://rays7.5rs.me/login')
    Login().login(user_name,password)
    # Create().create()
    # Code().code()
    # Give().give()
    Del().delete()
    DriverTools.quit_driver()