jumppage.py 1.02 KB
# -*- coding: utf-8 -*-
# @Time    :  2020/12/10 23:49
# @Author  :  Young Lee
# @Email   :  young_lee2017@163.com

import time


def jump_page(driver, large_module, small_module):
    """跳转到指定页面

    :param large_module: 大模块名称
    :param small_module: 子模块名称
    """
    large_xpath = f"//div[@class='el-submenu__title']//span[text()='{large_module}']"
    large_li_xpath = f"{large_xpath}/../.."
    small_xpath = f"//ul[@role='menu']/li[contains(text(),'{small_module}')]"

    if "is-opened" not in driver.find_element_by_xpath(large_li_xpath).get_attribute("class"):
        driver.find_element_by_xpath(large_xpath).click()

    if "is-active" not in driver.find_element_by_xpath(small_xpath).get_attribute("class"):
        time.sleep(0.5)
        driver.find_element_by_xpath(small_xpath).click()
    time.sleep(1)


if __name__ == "__main__":
    from unitinit import *
    login_fx(driver, login_url, user, passwd)
    jump_page(driver, '资源管理', '视频设备')
    time.sleep(3)
    driver.quit()