from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webdriver import WebDriver
class AddMember:
def __init__(self, driver: WebDriver):
self._driver = driver
def add_member(self):
sleep(3)
self._driver.find_element(By.ID, 'username').send_keys('halll')
self._driver.find_element(By.ID, 'memberAdd_acctid').send_keys('halll')
self._driver.find_element(By.ID, 'memberAdd_phone').send_keys('10000000000')
self._driver.find_element(By.XPATH,
'//*[@id="js_contacts63"]/div/div[2]/div/div[4]/div/form/div[3]/a[2]').click()
sleep(6)
self._driver.quit()
return True
def get_member(self):
elements = self._driver.find_elements(By.CSS_SELECTOR, '')
'''写法一'''
# list = []
# for element in elements:
# list.append(element.get_attribute("title"))
'''写法二'''
list = [element.get_attribute("title") for element in elements]
return list
main.py
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.options import Options
from seleniumTest.selenium_wework_main.page.add_member import AddMember
class Main:
def __init__(self):
options = Options()
options.debugger_address = "127.0.0.1:9222"
# self._driver = webdriver.Edge()
self._driver = webdriver.Edge(options=options)
self._driver.get("https://work.weixin.qq.com/wework_admin/frame")
def goto_add_member(self):
sleep(10)
self._driver.find_element(By.XPATH, '//*[@id="_hmt_click"]/div[1]/div[4]/div[2]/a[1]/div/span[2]')
sleep(2)
return AddMember(self._driver)
test_case
test_add_member.py
from time import sleep
from seleniumTest.selenium_wework_main.page.main import Main
class TestAddMember:
def setup(self):
self.main = Main()
def test_addmember(self):
add_member = self.main.goto_add_member()
add_member.add_member()
sleep(2)
assert "halll" in add_member.get_member()