rule_page.py
select_action =(By.ID,'ruleActionData_0_type')
# 定位添加执行动作
def locate_action(self,text):
self.add_action.click()
try:
WebDriverWait(self.driver, 60).until(
lambda driver: driver.execute_script('return document.readyState') == 'complete'
)
# 选择执行动作框
action = WebDriverWait(self.driver, 60).until(
# visibility_of_element_located方法接收
EC.element_to_be_clickable(self.select_action)
)
action.click()
WebDriverWait(self.driver, 60).until(
lambda driver: driver.execute_script('return document.readyState') == 'complete'
)
# 选择具体的动作
action_dialog = WebDriverWait(self.driver,60).until(
# visibility_of_element_located方法接收
EC.element_to_be_clickable(self.alert_dialog)
)
action_dialog.click()
WebDriverWait(self.driver, 60).until(
lambda driver: driver.execute_script('return document.readyState') == 'complete'
)
# 选择指定时机
time_dialog = WebDriverWait(self.driver, 60).until(
# visibility_of_element_located方法接收
EC.visibility_of_element_located(self.select_time)
)
time_dialog.click()
WebDriverWait(self.driver,60).until(
lambda driver: driver.execute_script('return document.readyState') == 'complete'
)
# 选择具体的时机
time_value = WebDriverWait(self.driver, 60).until(
# visibility_of_element_located方法接收
EC.visibility_of_element_located(self.select_time_value)
)
time_dialog.click()
time_value.click()
self.select_input=text
print("All elements clicked and inputs set successfully.")
except TimeoutException:
print("Element not found or not clickable within the given time.")
self.driver.save_screenshot('timeout_error.png')
except ElementClickInterceptedException:
print("Element click intercepted. Please check if any element is covering the target element.")
self.driver.save_screenshot('click_intercepted_error.png')
except NoSuchElementException:
print("Element not found with the specified criteria.")
self.driver.save_screenshot('no_such_element_error.png')
except Exception as e:
print(f"An unexpected error occurred: {e}")
self.driver.save_screenshot('unexpected_error.png')
raise
测试函数
@user1res("login")
def test_config_rule(login):
"""配置规则"""
# 调用封装函数进入app设置页面
enter_app_set(login, test_data['create_app']['appname'])
rule_page = RulePage(login)
rule_page.locate_rule()
rule_page.locate_child()
rule_page.locate_set_rule(test_data['rule']['field'])
time.sleep(5)
rule_page.locate_action(test_data['rule']['action'])
rule_page.locate_save()
rule_page.locate_action(test_data['rule']['action']) 这行代码一直是把执行动作弹框点击出来后,不执行下一步