1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import time
import openpyxl
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains


# 进入登陆界面
driver = webdriver.Edge()
mes = 'MES网址'
driver.get(mes)
time.sleep(1)

# 输入用户名
driver.find_element(By.ID,"userDto_loginName").send_keys("MES账号")
time.sleep(1)

# 输入密码
driver.find_element(By.ID,"keeper").send_keys("MES密码")
time.sleep(1)

# 选择账套
driver.find_element(By.ID,'mcDataAuthB').click()

# 空点
ActionChains(driver).move_by_offset(200,100).click().perform()
time.sleep(1)

# 点击登陆按钮
driver.find_element(By.ID, "loginButton").click()
time.sleep(3)

# 点击快捷方式
driver.find_element(By.ID, "infoDiv").click()
time.sleep(1)

# 点击库存查询
driver.find_element(By.XPATH, "/html/body/div[1]/div[1]/div/div[2]/div[3]/div/div[1]").click()
time.sleep(5)

# 进入库存查询框架
iframe = driver.find_element(By.ID, "iframe2")
driver.switch_to.frame(iframe)


# 查找当前文件夹.xlsx文件
path = os.getcwd()
files = os.listdir(path)
excelfiles = [f for f in files if not f.startswith(("~$")) and f.endswith((".xlsx"))]
for file in excelfiles:
fullpath = os.path.join(path,file)

# 打开.xlsx文件默认sheet
wb = openpyxl.load_workbook(fullpath)
sheet = wb.active


# 定义查找函数
def mes_clik(num):
cell = sheet["B" + str(num)].value
v = driver.find_element(By.XPATH, '/html/body/div[1]/div/div[2]/div/form/div/div[1]/div[1]/div/div[2]/div[3]/input[1]')
v.clear()
v.send_keys(cell)
time.sleep(1)

# 点击查询按钮
driver.find_element(By.XPATH, "/html/body/div[1]/div/div[2]/div/form/div/div[1]/div[2]/div[1]/a[1]").click()
name = sheet["A" + str(num)].value
num = sheet["C" + str(num)].value
print(str(cell) + '需要' + str(num))


# 循环查找物料信息
for i in range(2,100):
mes_clik(i)
input("按Enter键继续\n")