박시진

[Modify]Attendance function[failed]

......@@ -49,87 +49,123 @@ async function runrun() {
);
multipleClick(page);
// await page.type("Selector 입력", code);
// await page.click("확인버튼 selector");
await page.type("#crtfNo", code);
await page.click("#crtfBtn");
await page.click("body > div:nth-child(23) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button.di_btn_conf.ui-button.ui-widget.ui-state-default.ui-corner-all.ui-button-text-only");
await page.goto("https://portal.khu.ac.kr/haksa/clss/clss/elctCrtf/index.do");
result = await checkStatus(page);
console.log(result);
browser.close();
} catch (err) {
console.log(err);
}
}
async function multipleClick(page) {
let data = [];
let selector = "#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody";
const number = await page.$$eval(selector, (data) => data.length);
page.click("#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.first");
page.click("#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.last");
for (let index = 2; index < number; index++) {
page.click(`#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr:nth-child("+ ${index} +")`)
try{
for (let index = 2; index < number; index++) {
page.click(`#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr:nth-child("+ ${index} +") > td.first.input_td > a`)
}
page.click("#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.first > td.first.input_td > a");
page.click("#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.last > td.first.input_td > a");
}
catch(err){
console.log("error!");
}
}
async function checkStatus(page) {
let data = [];
let selector = "#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody";
const number = await page.$$eval(selector, (data) => data.length);
data.push(await except(page));
for (let index = 2; index < number; index++) {
data.push(await getOne(page, index));
if (await getOne(page, index) == "인증완료"){
return "success";
}
else{
return "failed";
}
}
// const promise3 = Promise.resolve(data);
// promise3.then(value => {
// for (let index = 0; index < value.length; index++) {
// if (value[index]=="출석완료") {
// return "success";
// }
// else{
// return "fail";
// }
// }
// })
return data;
}
async function except(page) {
let data = {};
//exception(first context)
let temp = await page.$(
"#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.first > td.td_btn"
"#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.first > td.first"
);
data.name = await page.evaluate((data) => {
data.push(data.textContent);
checking = await page.evaluate((data) => {
if (data.textContent == "인증완료"){
return "success";
}
else{
return "failed";
}
}, temp);
//exception(last context)
let templast = await page.$(
"#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.last > td.td_btn"
"#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.last > td.first"
);
data.name = await page.evaluate((data) => {
data.push(data.textContent);
checking = await page.evaluate((data) => {
if (data.textContent == "인증완료"){
return "success";
}
else{
return "failed";
}
}, templast);
return Promise.resolve(data);
}
}
async function getOne(page, index) {
let data = {};
let temp = await page.$(
"#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr:nth-child("+index+ ") > td.td_btn"
"#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr:nth-child("+index+ ") > td.first"
);
data.name = await page.evaluate((data) => {
checking = await page.evaluate((data) => {
return data.textContent;
}, temp);
return Promise.resolve(data);
return Promise.resolve(checking);
}
async function test() {
await runrun();
await attendanceCheck("오픈소스SW개발 00분반", 1234);
await attendanceCheck("오픈소스SW개발", 2022);
}
test();
\ No newline at end of file
test();
// //인증하기
// #baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.first > td.first.input_td > a
// #baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.first > td.first.input_td > a > span > b
// #baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.last > td.first
// //입력하기
// #crtfNo
// //인증 버튼 누르기
// #crtfBtn
// //확인
// body > div:nth-child(23) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button.di_btn_conf.ui-button.ui-widget.ui-state-default.ui-corner-all.ui-button-text-only
// //닫기
// body > div:nth-child(23) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button.di_btn_conf.ui-button.ui-widget.ui-state-default.ui-corner-all.ui-button-text-only
// //인증완료
// #baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.first > td.first
// #baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.last > td.first
// .name 사용
// page
\ No newline at end of file
......