| | |
| | | from selenium.common.exceptions import * |
| | | |
| | | import time |
| | | import re |
| | | |
| | | |
| | | class CIAQAnswerPage(BasePage): |
| | |
| | | """ |
| | | loading_count = 0 |
| | | |
| | | es = CIAQAnswerElements |
| | | elements = CIAQAnswerElements |
| | | |
| | | slice_count = 3 |
| | | |
| | | def answer(self): |
| | | # 暂停3秒 |
| | | for i in range(self.slice_count): |
| | | # 获取到题目 |
| | | time.sleep(3) |
| | | while True: |
| | | # 继续测试按钮出现则点击 |
| | | if self.continue_btn_is_display(): |
| | | self.click(self.es.continue_testing_btn) |
| | | title = self.get_ele(self.elements.q_title, 5) |
| | | # 截取已答数量与总数量 |
| | | match = re.search(r"(\d+)/(\d+)", title.text) |
| | | current = int(match.group(1)) |
| | | total = int(match.group(2)) |
| | | |
| | | # 标题不存在直接返回False |
| | | if not self.title_is_display(): |
| | | if self.continue_btn_is_display(): |
| | | self.click(self.es.continue_testing_btn) |
| | | continue |
| | | return False |
| | | |
| | | try: |
| | | while current <= total: |
| | | print(f"\n现在是CIAQ分片{i+1}第{current}题") |
| | | # 获取到所有选项 |
| | | options = self.get_eles(self.es.options) |
| | | options = self.get_eles(self.elements.options, 5) |
| | | number = random.randint(0, len(options)-1) |
| | | if options[number].is_enabled(): |
| | | options[number].click() |
| | | except: |
| | | pass |
| | | |
| | | # 提交按钮存在则点击 |
| | | if self.submit_btn_is_display(): |
| | | self.click(self.es.submit_btn) |
| | | # 数据是否上传完成 |
| | | time.sleep(15) |
| | | if self.upload_is_success(): |
| | | return True |
| | | return False |
| | | current += 1 |
| | | if (i + 1) != self.slice_count: |
| | | time.sleep(2) |
| | | # 点击继续测试 |
| | | self.click(self.elements.continue_testing_btn, 10) |
| | | time.sleep(2) |
| | | self.click(self.elements.submit_btn, 10) |
| | | |
| | | def upload_is_success(self): |
| | | """ |