# -*- coding:utf-8 -*-
# 作者：齐振鋆
# 日期：2022/9/23
import logging
import time

from selenium.webdriver.common.by import By

from unit.public.UI.BasePage import BasePage

log = logging.getLogger(__name__)


class MenuElement(BasePage):
    def open_menu(self, first_menu_name, last_menu_name):
        log.info('打开菜单：{}'.format(last_menu_name))
        # first_menu = "//div[contains(@class,'menuNavTop')]//div[text()='{}']".format(first_menu_name)
        # second_menu = "//div[contains(@class, 'third-menu') and @navname='{}']/ancestor::div[@class='sec-menu']".format(
        #     last_menu_name)
        # third_menu = "//div[contains(@class, 'third-menu') and @navname='{}']".format(last_menu_name)
        menu = f"//div[contains(@class, 'menu') and @navname='{last_menu_name}']/span"
        # self.move_to_element(first_menu)
        # self.move_to_element(second_menu)
        # self.click(third_menu) if self.wait_element(third_menu) else self.click(second_menu)

        driver = self.dd.get_value('driver')
        em = driver.find_element(By.XPATH, menu)
        time.sleep(3)
        driver.execute_script("arguments[0].click();", em)
        # self.js("arguments[0].click();", menu)
