import time
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
@pytest.fixture(scope='session')
def driver():
dr = webdriver.Chrome()
dr.maximize_window()
yield dr
time.sleep(30)
dr.quit()
@pytest.fixture()
def login(driver):
driver.get('http://www.baidu.com')
login_phone = (By.XPATH, '//form/div[1]/div/div/div/div/input')
login_pwd = (By.XPATH, '//input[@placeholder="请输入密码"]')
login_bt = (By.XPATH, '//form/div[4]/div/div[1]/div/button')
driver.find_element(*login_phone).send_keys('11111111111')
driver.find_element(*login_pwd).send_keys('654321')
driver.find_element(*login_bt).click()
@pytest.fixture()
def click_menu(driver, login):
def func(menu, sub_menu):
menu2 = "//*[text()=' " + menu + " ']"
ordermang = (By.XPATH, menu2)
baobeilist = (By.LINK_TEXT, sub_menu)
time.sleep(20)
driver.find_element(*ordermang).click()
driver.find_element(*baobeilist).click()
time.sleep(20)
return func