0
点赞
收藏
分享

微信扫一扫

软件测试面试题:如何判断一个页面上元素是否存在?(方法三)

如何判断一个页面上元素是否存在?(方法三)

方法三:结合WebDriverWait和expected_conditions判断

from selenium import webdriver

from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.support.ui import WebDriverWait

def is_element_exsist2(driver, locator):
'''\r\n 结合WebDriverWait和expected_conditions判断元素是否存在,
每间隔1秒判断一次,30s超时,存在返回True,不存返回False
:param locator: locator为元组类型,如("id", "yoyo")
:return: bool值,True or False
'''
try:
WebDriverWait(driver, 30, 1).until(EC.presence_of_element_located(locator))
return True
except:
return False
if __name__ == '__main__':
loc1 = ("id", "yoyo") # 元素1
print(is_element_exsist2(driver, loc1))


个人简介


我是一名测试兼开发工程师,目前25K,目前做的是无人驾驶,欢迎和大家一起交流测试技术,
起高薪就业,我们还有一起打妖怪的群哦,还有面试题小程序哦

举报

相关推荐

0 条评论