Python - itertools.product 遍历组合查询
# encoding:utf-8import unittest,time
from ddt import ddt, data, unpack, file_data
import itertools
from selenium import webdriver@ddt
class case(unittest.TestCase):def test1(self):self.dr = webdriver.Chrome()self.dr.maximize_window()self.dr.get('http://172.16.0.1/admin')self.dr.implicitly_wait(20)self.dr.find_element_by_id('txtName').send_keys('admin')self.dr.find_element_by_id('txtPwd').send_keys('1')self.dr.find_element_by_id('fm-login-submit').click()time.sleep(2)self.dr.find_element_by_id('mumu_group100001400').click()time.sleep(1)self.dr.find_element_by_id('left_100001400').click()time.sleep(1)self.dr.find_element_by_id('left_101016100').click()time.sleep(3)self.dr.switch_to_frame(1)# 会员卡号#self.dr.find_element_by_id("txtLeaguerCode").send_keys(phone)# 会员姓名#self.dr.find_element_by_id("txtLeaguergName").send_keys(name)# 账期a = ['//*[@id="asd1fgh3jkldll1"]/div/div/ul/li[1]','//*[@id="asd1fgh3jkldll1"]/div/div/ul/li[2]','//*[@id="asd1fgh3jkldll1"]/div/div/ul/li[3]','//*[@id="asd1fgh3jkldll1"]/div/div/ul/li[4]']# 类型b = ['//*[@id="IsChange"]/div/div/ul/li[2]', '//*[@id="IsChange"]/div/div/ul/li[3]']for x in itertools.product(a, b):# 点击账期下拉框self.dr.find_element_by_xpath('//*[@id="asd1fgh3jkldll1"]/div/div').click()time.sleep(1)# 遍历选择下拉框元素self.dr.find_element_by_xpath(x[0]).click()# 点击类型下拉框self.dr.find_element_by_xpath('//*[@id="IsChange"]/div/div/button').click()time.sleep(1)# 遍历选择类型下拉框元素self.dr.find_element_by_xpath(x[1]).click()# 点击查询self.dr.find_element_by_xpath('/html/body/div[1]/div[6]/button[1]').click()