码迷,mamicode.com
首页 > 其他好文 > 详细

selenium--等待时间

时间:2019-06-12 18:16:28      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:div   alert   使用   web   class   bsp   返回   contain   selection   

#####################################################
## 等待时间
#####################################################

"""
expected_conditions 类提供的常见方法
title_is()  判断标题是否等于预期值。
title_contains()  判断标题是否包含预期结果。
presence_of_element_located((By.ID,‘id1‘))  判断元素是否存在,并返回该元素。
visibility_of_element_located()  判断元素是否可见。
visibility_of()  判断元素是否可见
presence_of_all_elements_located()  判断一组元素的是否存在,并返回元素组
text_to_be_present_in_element((By.ID,‘id1‘),‘菠萝壳‘)  判断元素text值是否包含预期文本信息
text_to_be_present_in_element_value()  判断元素value值是否包含预期文本信息
frame_to_be_available_and_switch_to_it()  表单是否可用,并切换到该表单。
invisibility_of_element_located()  判断元素是否隐藏
element_to_be_clickable()  判断元素是否点击,它处于可见和启动状态
staleness_of()  等到一个元素不再是依附于DOM。
element_to_be_selected()  判断某个元素是否被选中。
element_located_to_be_selected()  一个期望的元素位于被选中。
element_selection_state_to_be()  判断某个元素的选中状态是否符合预期。
element_located_selection_state_to_be()  判断某个元素的选中状态是否符合预期,并返回定位
alert_is_present()  判断页面是否存在警告框 
"""

### 显示等待/步骤等待
## 等待某一个对象的某一属性出现某一个值

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

b = webdriver.Chrome()
b.implicitly_wait(1)
b.get(file:///E:/ZM20190316/2.Selenium/TestDemo/waitForDemo/waitForDemo.htm)
b.maximize_window()

b.find_element_by_xpath(/html/body/form/input[2]).click()

# 第一种方法:使用lambda匿名函数
# ta_text = WebDriverWait(b,30,0.5).until(lambda b:b.find_element_by_id(‘id2‘))

# 第二种方法:使用EC类
ipt_text = (By.NAME,t1)
WebDriverWait(b,30,0.5).until(EC.text_to_be_present_in_element_value(ipt_text,populated))

ta_text = b.find_element_by_id(id2)
print(ta_text.text)

sleep(3)
b.quit()

 

selenium--等待时间

标签:div   alert   使用   web   class   bsp   返回   contain   selection   

原文地址:https://www.cnblogs.com/chen-huan/p/11010985.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!