博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python+Selenium练习篇之19-断言页面标题
阅读量:4301 次
发布时间:2019-05-27

本文共 643 字,大约阅读时间需要 2 分钟。

本文绍一个Selenium中页面title断言方法,这个在基础篇中第一个完整的脚本有提到过,这个补充一下。

相关脚本代码如下:

# coding=utf-8import timefrom selenium import webdriverdriver = webdriver.Chrome()driver.maximize_window()driver.get('https://www.baidu.com')time.sleep(1)# 方法一try:    assert u"百度一下" in driver.title    print ('Assertion test pass.')except Exception as e:    print ('Assertion test fail.', format(e))# 方法二if u"百度一下,你就知道" == driver.title :    print ('Assertion test pass.')else:    print ('Assertion test fail.')print driver.title
方法一,是利用python中Assert方法,采用包含判断,方法二是通过if方法,采用完全相等方法,建议选择第一种方法。
u"百度一下,你就知道"
这u代表unicode的意思,由于我们这里采用了python 2, 如果你使用pyn3 就不需要,在Python3中,字符串默认采用unicode存储。

转载地址:http://ugxws.baihongyu.com/

你可能感兴趣的文章
【2020-3-21】Mac安装Homebrew慢,解决办法
查看>>
influxdb 命令行输出时间为 yyyy-MM-dd HH:mm:ss(年月日时分秒)的方法
查看>>
已知子网掩码,确定ip地址范围
查看>>
判断时间或者数字是否连续
查看>>
docker-daemon.json各配置详解
查看>>
Mac 下docker路径 /var/lib/docker不存在问题
查看>>
Docker(一)使用阿里云容器镜像服务
查看>>
Docker(二) 基础命令
查看>>
Docker(三) 构建镜像
查看>>
Spring 全家桶注解一览
查看>>
JDK1.8-Stream API使用
查看>>
cant connect to local MySQL server through socket /tmp/mysql.sock (2)
查看>>
vue中的状态管理 vuex store
查看>>
Maven之阿里云镜像仓库配置
查看>>
Maven:mirror和repository 区别
查看>>
微服务网关 Spring Cloud Gateway
查看>>
SpringCloud Feign的使用方式(一)
查看>>
SpringCloud Feign的使用方式(二)
查看>>
关于Vue-cli+ElementUI项目 打包时排除Vue和ElementUI
查看>>
Vue 路由懒加载根据根路由合并chunk块
查看>>