Python+Selenium 自动化实现实例-处理分页(pagination)
场景
对分页来说,我们最感兴趣的是下面几个信息
- 总共有多少页
- 当前是第几页
- 是否可以上一页和下一页
代码
下面代码演示如何获取分页总数及当前页数、跳转到指定页数
#coding:utf-8
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get("https://segmentfault.com/news")
# 获得所有分页的数量
# -2是因为要去掉上一个和下一个
total_pages = len(driver.find_element_by_class_name("pagination").find_elements_by_tag_name("li"))-2
print "total_pages is %s" %(total_pages)
# 获取当前页面是第几页
current_page = driver.find_element_by_class_name('pagination').find_element_by_class_name('active')
print "current page is %s" %(current_page.text)
#跳转到第二页
next_page = driver.find_element_by_class_name("pagination").find_element_by_link_text("2")
next_page.click()
##等待3秒,退出浏览器
time.sleep(3)
driver.quit()
原文文章地址:http://www.cnblogs.com/forcepush/p/6650123.html
*{
margin-left: -8px;
}
-->
Python+Selenium 自动化实现实例-处理分页(pagination)的更多相关文章
- Python+Selenium 自动化实现实例-实现文件下载
#coding=utf-8 from selenium import webdriver #实例化一个火狐配置文件 fp = webdriver.FirefoxProfile() #设置各项参数,参数 ...
- Python+Selenium 自动化实现实例-Css捕捉元素的几种方法
#coding=utf-8 from selenium import webdriverimport timedriver = webdriver.Chrome()driver.get("h ...
- Python+Selenium 自动化实现实例-打开浏览器模拟进行搜索数据并验证
#导入模块 from selenium import webdriverfrom selenium.webdriver.common.keys import Keys #启动火狐浏览器driver = ...
- Python+Selenium 自动化实现实例-定位frame中的元素
场景 处理frame需要用到2个方法,分别是switch_to_frame(name_or_id_or_frame_element)和switch_to_default_content() 如何理解这 ...
- Python+Selenium 自动化实现实例-单元测试报告
代码如下: # -*- coding: utf-8 -*- from selenium import webdriver import unittest,time import HTMLTestRun ...
- Python+Selenium 自动化实现实例-模块化调用
public 目录存一些公共模块,供用例调用.login.py 内容如下: # coding=utf-8 import time # login def login(driver): driver.f ...
- Python+Selenium 自动化实现实例-数据驱动实例
#coding=utf-8 from selenium import webdriver driver = webdriver.Firefox() driver.implicitly_wait(10) ...
- Python+Selenium 自动化实现实例-获取测试对象的Css属性
#coding:utf-8 '''获取测试对象的css属性场景 当你的测试用例纠结细枝末节的时候,你就需要通过判断元素的css属性来验证你的操作是否达到了预期的效果.比如你可以通过判断页面上的标题字号 ...
- Python+Selenium 自动化实现实例-定位一组对象(checkbox,inputs)
# -*- coding: utf-8 -*- from selenium import webdriver import time import os dr = webdriver.Chrome() ...
随机推荐
- (转)并发编程 – Concurrent 用户指南
原文出处: 高广超 译序 本指南根据 Jakob Jenkov 最新博客翻译,请随时关注博客更新:http://tutorials.jenkov.com/java-util-concurrent/in ...
- OpenCV中Mat的使用
一.数字图像存储概述 数字图像存储时,我们存储的是图像每个像素点的数值,对应的是一个数字矩阵. 二.Mat的存储 1.OpenCV1基于C接口定义的图像存储格式IplImage*,直接暴露内存,如果忘 ...
- Java学习笔记——鸵鸟学习记(二)
---恢复内容开始--- 4. 数组对象 4.1 数组的创建 a, 数组对象 在Java语言中,数组对象可以表示一组数字. int[] arr = new int[30];(new可以表示为创建 ...
- python对mysql进行简单操作
python 连接MySQL数据库,进行简单操作 一.连接MySQL数据库,关闭连接 import pymysql db = pymysql.connect(host="xxx.xxx.x. ...
- PackagesNotFoundError: The following packages are not available from current channels
因为要用到lifelines 包,在cmd中使用conda install lifelines ,显示如下错误: PackagesNotFoundError: The following packag ...
- 简单封装Redis做缓存
基于Redis封装一个简单的Python缓存模块 0. Docker Redis安装 参考: Get Docker CE for CentOS Docker 安装 Redis 安装Docker时错误s ...
- Linux下查看tomcat版本
进入到tomcat的bin目录下,再执行./version.sh tomcat版本:7.0
- 深入理解Java虚拟机读书笔记4----虚拟机类加载机制
四 虚拟机类加载机制 1 类加载机制 ---概念:虚拟机把描述类的数据从Class文件加载到内存,并对数据进行校验.转换解析和初始化,最终形成可以被虚拟机直接使用的Java类型. -- ...
- CentOS7.0 采用压缩包 安装Nginx 1.7.4和添加Tomcat为系统服务 nginx结合tomcat
CentOS7.0 采用压缩包 安装Nginx 1.7.4 一.安装准备首先由于nginx的一些模块依赖一些lib库,所以在安装nginx之前,必须先安装这些lib库,这些依赖库主要有g++.gcc ...
- redis+thinkphp5的注册、登陆、关注基础例子
最近初步接触redis,结合thinkphp5与redis,写了一个用户注册的基础例子,用于学习. 这个例子是结合了兄弟连的redis视频,最后两节的内容写的:https://study.163.co ...