弹窗处理
''' select_by_index() # 通过索引定位-选项 select_by_value() # 通过value值定位-选项 select_by_visible_text() # 通过文本值定位-选项 deselect_all() # 取消所有选项 deselect_by_index() # 取消对应index选项 deselect_by_value() # 取消对应value选项 deselect_by_visible_text() # 取消对应文本选项 options() # 返回下拉列表-所有选项 first_selected_option() # 返回下拉列表-第一个选项 all_selected_options() # 返回下拉列表-选中的选项 ''' #select标签下拉框 索引定位,通过索引定位-选项 def select_index(by, locator, value): try: k = get_element(driver, by, locator) Select(k).select_by_index(value) k.click() except Exception as e: raise e ''' #定位非<select>标签的下拉菜单 # 先定位到下拉菜单 #drop_down = driver.find_element_by_css_selector("div#select2_container > ul") # 再对下拉菜单中的选项进行选择 #drop_down.find_element_by_id("li2_input_2").click() #div标签#id名称 > 下拉标签尾 #li标签中的id def select_css(value1,value2): try: drop_down = driver.find_element_by_css_selector(value1) drop_down.find_element_by_id(value2).click() print("选择成功") except Exception as e: print(e) ''' #移除日历框只读属性,定位输入 def remove_jQuery(by,locator,value): try: js = "$('input:eq(0)').removeAttr('readonly')" # jQuery,移除属性 driver.execute_script(js) print("JS执行成功") get_element(driver, by, locator).send_keys(value) except Exception as e: print(e) # 获取元素文本值 def get_text(by, locator,value): try: text = get_element(driver, by, locator).text print(text) assert text == value except Exception as e: raise e #弹框警告-确认 def alert_Accept(): try: # self.driver.switch_to_alert().accept() 废弃的方式 driver.switch_to.alert.accept() except Exception as e: raise e #弹框警告-取消 def alert_Dismiss(): try: # self.driver.switch_to_alert().dismiss() 废弃的方式 driver.switch_to.alert.dismiss() except Exception as e: raise e #获取alert弹窗文本内容 def alert_text(value): try: txt = driver.switch_to.alert.text() assert txt == value except Exception as e: raise e #超时会消失的提醒弹窗,提示之前先设置隐式等待,后提取提示文本 #在点击登录后,使用implicitly_wait()设置隐式等待时间,后接提示文本的获取就可以了 #https://testerhome.com/topics/18955?locale=zh-CN def assert_toast_text(by,locator,vaule): try: #wait(5) txt = get_element(driver, by, locator).text print(txt) if txt == vaule: print("提示信息正确") else: print("提示信息错误") except Exception as e: raise e
心之所向无人可挡