企业微信的自动化登陆2

image

课后调查表:https://hogwarts.jinshuju.com/f/OwtF8m

课间作业

selenium 实现企业微信登录后的 po 封装

import time
from selenium import webdriver

class CompanyWeixin:

    def __init__(self):
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.get("'https://work.weixin.qq.com/'")
        self.driver.implicitly_wait(5)

    def first_page(self):
        """
        首页PO
        :return:
        """
        self.driver.find_element_by_xpath('//*[@id="_hmt_click"]/div[1]/div[4]/div[2]/a[1]/div/span[2]').click()
        time.sleep(1)
        self.driver.find_element_by_id('username').send_keys("tester")
        self.driver.find_element_by_id("memberAdd_english_name").send_keys("tester")
        self.driver.find_element_by_id("memberAdd_acctid").send_keys("tester")
        self.driver.find_element_by_name("mobile").send_keys('14787184017')
        self.driver.find_element_by_xpath('//*[@id="js_contacts40"]/div/div[2]/div/div[4]/div/form/div[3]/a[2]').click()
        time.sleep(1)
        

    def contact_book(self):
        """
        通讯录PO
        :return:
        """
        pass

    def app_manage(self):
        """
        应用管理PO
        :return:
        """
        pass

    def customer_manage(self):
        """
        客户管理PO
        :return:
        """
        pass

    def manage_tool(self):
        """
        管理工具PO
        :return:
        """
        pass

    def my_company(self):
        """
        我的企业PO
        :return:
        """
        pass




from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

from selenium_test.otherPOs import AddMemeber, Address, MemeberJoin


class Index:
    """
    登录后的微信PO封装
    """
    def __init__(self):
        options = Options()
        options.debugger_address = "127.0.0.1:9222"
        self.driver = webdriver.Chrome(options)
        self.driver.get("https://work.weixin.qq.com/wework_admin/frame")

    def goto_addmember(self):
        """
        去往添加成员 PO
        :return:
        """
        self.driver.find_element(By.CSS_SELECTOR, ".index_service_cnt_item_title").click()
        return AddMemeber()

    def goto_address(self):
        """
        去往 添加通信录 PO
        :return:
        """
        self.driver.find_element(By.XPATH, '//span[@class="ww_indexImg ww_indexImg_Import"]/following-sibling::*').click()
        return Address()

    def goto_memeber_join(self):
        """
        去往 成员加入 PO
        :return:
        """
        self.driver.find_element(By.XPATH,
                                 '//span[@class="ww_indexImg ww_indexImg_MemberJoin"]/following-sibling::*').click()
        return MemeberJoin()

补一个作业

from selenium.webdriver.chrome.webdriver import WebDriver
from selenium import webdriver
from selenium.webdriver.common.by import By

from web.afterlogin.add_member import AddMember
from web.afterlogin.checkin import Checkin
from web.afterlogin.custom_contact import CustomContact
from web.afterlogin.import_contacts import ImportContacts
from web.afterlogin.member_join import MemberJoin
from web.afterlogin.message_broadcast import MessageBroadcast


class Index(object):
    def __init__(self, driver: WebDriver = None):
        self.driver = driver if driver is not None else webdriver.Chrome()

    def to_add_member(self):
        xpath_click(self.driver, '//*[@id="_hmt_click"]/div[1]/div[4]/div[2]/a[1]')
        return AddMember(self.driver)

    def to_import_contacts(self):
        xpath_click(self.driver, '//*[@id="_hmt_click"]/div[1]/div[4]/div[2]/a[2]')
        return ImportContacts(self.driver)

    def to_member_join(self):
        xpath_click(self.driver, '//*[@id="_hmt_click"]/div[1]/div[4]/div[2]/a[3]')
        return MemberJoin(self.driver)

    def to_message_broadcast(self):
        xpath_click(self.driver, '//*[@id="_hmt_click"]/div[1]/div[4]/div[2]/a[4]')
        return MessageBroadcast(self.driver)

    def to_custom_contact(self):
        xpath_click(self.driver, '//*[@id="_hmt_click"]/div[1]/div[4]/div[2]/a[5]')
        return CustomContact(self.driver)

    def to_checkin(self):
        xpath_click(self.driver, '//*[@id="_hmt_click"]/div[1]/div[4]/div[2]/a[6]')
        return Checkin(self.driver)


def xpath_click(driver: WebDriver, xpath):
    return driver.find_element(By.XPATH, xpath).click()


if __name__ == '__main__':
    index = Index()
    index.to_import_contacts().to_goback()

关闭