当前位置:网站首页>selenium之预期条件判断方法
selenium之预期条件判断方法
2022-04-22 15:55:00 【qq_33808440】
expected_conditions 类提供的预期条件判断方法
一. title_is
判断当前页面的标题是否等于预期
expected_conditions.title_is(“预期的网页标题全部内容”)(driver)
源码:
class title_is(object):
"""An expectation for checking the title of a page.
title is the expected title, which must be an exact match
returns True if the title matches, false otherwise."""
def __init__(self, title):
self.title = title
def __call__(self, driver):
return self.title == driver.title
实例:
from selenium import webdriver
from selenium.webdriver.support import expected_conditions
driver = webdriver.Chrome()
driver.get("http://www.baidu.com")
res = expected_conditions.title_is("百度一下,你就知道")(driver)
print(res)
二. title_contains
判断当前页面的标题是否包含预期字符串
三. presence_of_element_located
判断元素是否被加在 DOM 树里,并不代表该元素一定可见;
返回对应的元素对象;
需要导入:from selenium.webdriver.common.by import By
源码:
class presence_of_element_located(object):
""" An expectation for checking that an element is present on the DOM
of a page. This does not necessarily mean that the element is visible.
locator - used to find the element
returns the WebElement once it is located
"""
def __init__(self, locator):
self.locator = locator
def __call__(self, driver):
return _find_element(driver, self.locator)
def _find_element(driver, by):
"""Looks up an element. Logs and re-raises ``WebDriverException``
if thrown."""
try:
return driver.find_element(*by)
except NoSuchElementException as e:
raise e
except WebDriverException as e:
raise e
实例:
# 返回的res是这个元素;如果没这个元素则抛异常
res = expected_conditions.presence_of_element_located((By.XPATH ,"//input[@id='kw']"))(driver)
print(res)
四. visibility_of_element_located
判断元素是否可见(可见代表元素非隐藏,并且元素的宽和高都不等
于 0)
五. visibility_of
与上一个方法作用相同,上一个方法的参数为定位,该方法接收的参
数为定位后的元素
六. presence_of_all_elements_located
判断是否至少有一个元素存在于 DOM 树中。例如,在页面中有 n 个元
素的 class 为“wp”,那么只要有一个元素存在于 DOM 树中就返回 True
七. text_to_be_present_in_element
判断某个元素中的 text 是否包含预期的字符串
八. text_to_be_present_in_element_value
判断某个元素的 value 属性是否包含预期的字符串
九. frame_to_be_available_and_switch_to_it
判断该表单是否可以切换进去,如果可以,返回 True 并且切换进去,
否则返回 False
十. invisibility_of_element_located
判断某个元素是否不在 DOM 树中或不可见
十一. element_to_be_clickable
判断某个元素是否可见并且是可以点击的
十二. staleness_of
等到一个元素从 DOM 树中移除
十三. element_to_be_selected
判断某个元素是否被选中,一般用在下拉列表中
十四. element_selection_state_to_be
判断某个元素的选中状态是否符合预期
十五. element_located_selection_state_to_be
与上一个方法作用相同,只是上一个方法参数为定位后的元素,该方
法接收的参数为定位
十六. alert_is_present
判断页面上是否存在 alert
版权声明
本文为[qq_33808440]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_33808440/article/details/119356304
边栏推荐
- 阿里云国际版设置电子邮件托管教程详解
- ‘telnet‘ 不是内部或外部命令也不是可运行的程序或批处理文件
- For the professional development of teacher Guo, write down your experience
- 对线郭老师职业发展,记下自己的心得体会
- Rust异步框架的性能评估
- The translation uses Prometheus and grafana to realize SLO
- Malware analysis – ursnif Trojan
- 快速搭建属于你自己的WordPress博客站点【玩转华为云】
- Construction method and process of enterprise level knowledge management (km)
- 引入文件路径问题-$_SERVER[‘DOCUMENT_ROOT‘]代表网站根目录
猜你喜欢

性能飙升66%的秘密:AMD 2.5万元768MB 3D缓存霄龙首次开盖

推进制造业数字化转型的几个建议
How redis solves the performance bottleneck caused by frequent command round trips!

【基于合泰HT32F52352+oled温湿度显示】

Graphics 101 matrix transformation (sections 2-4)

CASIA webface of dataset: a detailed introduction to the introduction, installation and use of CASIA webface dataset

SAP UI5 应用开发教程之七十一 - SAP UI5 页面的嵌套路由试读版

SQL statement - multi table joint query

Immundiagnostik IDK TurbiPEL测定分析

网站优化后如何降低阿里云国际版服务器成本
随机推荐
太卷了~(2022版)大厂面经 + 详细笔记帮你搞定面试
Spark基础学习笔记23:DataFrame与Dataset
Altium designer除了GND以外的Nets自动布线
Reverse linked list (and) the intermediate node of the linked list
显示是否紧急
使用js完成文字根据输入框内数字在屏幕上移动
SAP UI5 应用开发教程之七十一 - SAP UI5 页面的嵌套路由
阿里P9手写39模块Redis核心笔记,吃透笔记我面试成功涨薪7K
短信平台API接口demo示例-Node/SMS/Send
Dongfeng Nissan recalls some Xiaoke with potential safety hazards
生物素-4-荧光素实验注意事项
jsquery.xxx.js和jsquery.xxx.min.js的区别
Grafana 系列文章(九):开源云原生日志解决方案 Loki 简介
Malware analysis – ursnif Trojan
[yolact dataset production - detailed explanation of labelme use and conversion to coco]
Frequently asked questions about recent BSN development
基于移动目标防御(MTD)的终端安全解决方案
sql語句———多錶聯查
MySQL operator explanation and regular expression query
制作的自媒体短视频很模糊?教你3个方法,让视频变清晰