| | |
| | | from base.base_page import BasePage |
| | | from elements.maq_answer_elements import MAQAnswerElements |
| | | from selenium.common.exceptions import * |
| | | |
| | | import time |
| | | import re |
| | | |
| | | |
| | | class MAQAnswerPage(BasePage): |
| | |
| | | |
| | | se = MAQAnswerElements |
| | | |
| | | def answer(self, hint=None, question: dict = None): |
| | | tip_timing = 35 |
| | | |
| | | def exercise_answer(self): |
| | | # 获取到题目 |
| | | time.sleep(3) |
| | | title = self.get_ele(self.se.q_title, 5) |
| | | # 截取已答数量与总数量 |
| | | match = re.search(r"(\d+)/(\d+)", title.text) |
| | | current = int(match.group(1)) |
| | | total = int(match.group(2)) |
| | | |
| | | while current <= total: |
| | | # 获取到所有选项 |
| | | options = self.get_eles(self.se.options, 5) |
| | | number = random.randint(0, 5) |
| | | if options[number].is_enabled(): |
| | | options[number].click() |
| | | current += 1 |
| | | continue |
| | | time.sleep(3) |
| | | # 点击提交按钮 |
| | | self.click(self.se.exercise_submit_btn, 10) |
| | | |
| | | def answer(self): |
| | | # 获取到题目 |
| | | time.sleep(3) |
| | | title = self.get_ele(self.se.q_title, 5) |
| | | # 截取已答数量与总数量 |
| | | match = re.search(r"(\d+)/(\d+)", title.text) |
| | | current = int(match.group(1)) |
| | | total = int(match.group(2)) |
| | | |
| | | while current <= total: |
| | | print(f"\n现在是第{current}题") |
| | | # 触发事中 |
| | | if current == self.tip_timing: |
| | | time.sleep(5) |
| | | self.click(self.se.continue_testing_btn, 10) |
| | | |
| | | # 获取到所有选项 |
| | | options = self.get_eles(self.se.options, 5) |
| | | number = random.randint(0, 5) |
| | | if options[number].is_enabled(): |
| | | options[number].click() |
| | | current += 1 |
| | | continue |
| | | |
| | | time.sleep(3) |
| | | # 点击提交按钮 |
| | | self.click(self.se.submit_btn, 10) |
| | | # while True: |
| | | # # 获取到所有选项 |
| | | # options = self.get_eles(self.se.options) |
| | | # if len(options) < 6: |
| | | # continue |
| | | # number = random.randint(0, 5) |
| | | # if options[number].is_enabled(): |
| | | # # 获取到题目 |
| | | # q_title = self.get_ele(self.se.q_title).text |
| | | # # q_title与question_title不相同则写入question中 |
| | | # # 遍历字典 |
| | | # # if question: |
| | | # # for key in question.keys(): |
| | | # # q_title = self.get_ele(self.se.q_title).text |
| | | # # if question[key]["title"] in q_title and "answer" not in question[key]: |
| | | # # question[key]["answer"] = number + 1 |
| | | # # question_title = q_title |
| | | # # break |
| | | # options[number].click() |
| | | # |
| | | # # 提交按钮存在则点击 |
| | | # if self.submit_btn_is_display(): |
| | | # self.click(self.se.submit_btn) |
| | | # # 数据是否上传完成 |
| | | # time.sleep(15) |
| | | # if self.upload_is_success(): |
| | | # if hint: |
| | | # return flag |
| | | # return True |
| | | # # 是否网络异常 |
| | | # try: |
| | | # self.get_ele(self.se.network_exception_title) |
| | | # return "网络异常" |
| | | # except NoSuchElementException: |
| | | # pass |
| | | # return False |
| | | |
| | | def answer2(self, hint=None, question: dict = None): |
| | | flag = False |
| | | # 暂停3秒 |
| | | time.sleep(3) |
| | | # 点击开始答题 |
| | | self.click(self.se.start_btn) |
| | | question_title = None |
| | | while True: |
| | | # time.sleep(0.5) |