-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
78 lines (67 loc) · 3.8 KB
/
main.py
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
from data_extract import pub_data_dict
# Generated by Selenium IDE
import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.select import Select
from selenium.common.exceptions import NoSuchElementException
import sys
class Main():
def setup_method(self, method = None):
self.driver = webdriver.Chrome()
self.vars = {}
self.driver.implicitly_wait(5)
def teardown_method(self, method = None):
self.driver.quit()
def wait_for_window(self, timeout = 2):
time.sleep(round(timeout / 1000))
wh_now = self.driver.window_handles
wh_then = self.vars["window_handles"]
if len(wh_now) > len(wh_then):
return set(wh_now).difference(set(wh_then)).pop()
def migrateStudent(self):
self.driver.get("https://alyecs135.xnzn.net/#/personal/personnal")
self.driver.set_window_size(1800, 1055)
time.sleep(20)
self.driver.find_element(By.CSS_SELECTOR, ".active:nth-child(1) > span").click()
self.driver.find_element(By.CSS_SELECTOR, "div:nth-child(8) > .el-menu-item > span").click()
self.driver.find_element(By.CSS_SELECTOR, "div:nth-child(3) a > span").click()
for i in range(len(pub_data_dict['School_ID'])):
row_data = {header: values[i] for header, values in pub_data_dict.items()}
stu_id = row_data['School_ID']
print("当前处理学生", stu_id)
self.driver.find_element(By.CSS_SELECTOR, ".el-col:nth-child(1) .el-form-item__content > .el-input > .el-input__inner").click()
self.driver.find_element(By.CSS_SELECTOR, ".el-col:nth-child(1) .el-form-item__content > .el-input > .el-input__inner").clear()
self.driver.find_element(By.CSS_SELECTOR, ".el-col:nth-child(1) .el-form-item__content > .el-input > .el-input__inner").send_keys(stu_id)
self.driver.find_element(By.CSS_SELECTOR, ".el-button--success:nth-child(2) > span").click()
click_editor = self.driver.find_element(By.XPATH, "/html/body/div/div/div[2]/div[2]/section/div/section/main/div[1]/div[1]/div[5]/div[2]/table/tbody/tr/td[23]/div/button[3]/span")
self.driver.execute_script("arguments[0].click();", click_editor)
self.driver.find_element(By.CSS_SELECTOR, ".is-required .el-cascader .el-input__inner").click()
click_group = self.driver.find_element(By.XPATH, "//div[2]/div/ul/li[9]/label/span/span")
self.driver.execute_script("arguments[0].click();", click_group)
click_group = self.driver.find_element(By.XPATH, "//div[3]/div/ul/li[7]/label/span/span")
self.driver.execute_script("arguments[0].click();", click_group)
self.driver.find_element(By.CSS_SELECTOR, ".el-dialog__footer:nth-child(3) .el-button--primary > span").click()
self.driver.find_element(By.CSS_SELECTOR, ".el-col:nth-child(1) .el-form-item__content > .el-input > .el-input__inner").click()
if __name__ == "__main__":
test = Main()
test.setup_method()
print("自动化开始")
start_time = time.time()
test.migrateStudent()
time.sleep(2)
test.teardown_method()
# 计算执行时间
end_time = time.time()
execution_time = end_time - start_time
print(f"程序执行时间:{execution_time}秒")
print("自动化结束")