场景

对分页来说,我们最感兴趣的是下面几个信息

  • 总共有多少页
  • 当前是第几页
  • 是否可以上一页和下一页

代码

下面代码演示如何获取分页总数及当前页数、跳转到指定页数

#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)的更多相关文章

  1. Python+Selenium 自动化实现实例-实现文件下载

    #coding=utf-8 from selenium import webdriver #实例化一个火狐配置文件 fp = webdriver.FirefoxProfile() #设置各项参数,参数 ...

  2. Python+Selenium 自动化实现实例-Css捕捉元素的几种方法

    #coding=utf-8 from selenium import webdriverimport timedriver = webdriver.Chrome()driver.get("h ...

  3. Python+Selenium 自动化实现实例-打开浏览器模拟进行搜索数据并验证

    #导入模块 from selenium import webdriverfrom selenium.webdriver.common.keys import Keys #启动火狐浏览器driver = ...

  4. Python+Selenium 自动化实现实例-定位frame中的元素

    场景 处理frame需要用到2个方法,分别是switch_to_frame(name_or_id_or_frame_element)和switch_to_default_content() 如何理解这 ...

  5. Python+Selenium 自动化实现实例-单元测试报告

    代码如下: # -*- coding: utf-8 -*- from selenium import webdriver import unittest,time import HTMLTestRun ...

  6. Python+Selenium 自动化实现实例-模块化调用

    public 目录存一些公共模块,供用例调用.login.py 内容如下: # coding=utf-8 import time # login def login(driver): driver.f ...

  7. Python+Selenium 自动化实现实例-数据驱动实例

    #coding=utf-8 from selenium import webdriver driver = webdriver.Firefox() driver.implicitly_wait(10) ...

  8. Python+Selenium 自动化实现实例-获取测试对象的Css属性

    #coding:utf-8 '''获取测试对象的css属性场景 当你的测试用例纠结细枝末节的时候,你就需要通过判断元素的css属性来验证你的操作是否达到了预期的效果.比如你可以通过判断页面上的标题字号 ...

  9. Python+Selenium 自动化实现实例-定位一组对象(checkbox,inputs)

    # -*- coding: utf-8 -*- from selenium import webdriver import time import os dr = webdriver.Chrome() ...

随机推荐

  1. Koa,React和socket.io

    安装  socket.io/socket.io-client 基本用法 首先koa和socket.io代码片段 const server = require('http'). const server ...

  2. xml 转换成对象(采用反射机制对对对象属性赋值)

    /// <summary> /// 采用反射机制对对对象属性赋值 /// </summary> /// <param name="node">& ...

  3. 【转载】Google 程序员消灭 Bug 的 5 大法宝!

    遇到问题怎么办?还能怎么办,解决呗.那到底怎么解决呢?你是有什么惯用的逻辑模式.解决策略,还是全靠直觉手感? 本文中,一位 Google 程序员将“现场”演示其解决编程问题的始末,看看有套路的问题解决 ...

  4. hadoop单机模式安装流程

    这里的安装是在Linux系统上安装的 参考博客 : https://blog.csdn.net/cafebar123/article/details/73500014 https://blog.csd ...

  5. V先生:信息流广告标题党必备的500个热词

    稍微没有全都偏,简直仅仅只永远, 已经曾经就竟然,将要立刻刚偶然, 渐渐终于决忽然,难道连续又再三, 也许必须很非常,最太十分更马上, 越极总挺常常再,屡次一定也不还. 你一定不知道.如何.最.咋.是 ...

  6. python 虚拟环境使用与管理(virtualenv)

    安装虚拟环境 pip install virtualenv 安装虚拟环境管理工具 pip install virtualenvwrapper-win 设置虚拟环境目录(虚拟环境存放位置) 默认创建的虚 ...

  7. xml模块学习

    import xml.etree.ElementTree as ET tree = ET.parse("xmltest.xml") root = tree.getroot() pr ...

  8. UVa514 Rails (栈)

    题意:一列有n节车厢的火车按顺序进站,给你一个出站顺序,问你该火车的车厢能否以该顺序出站? 分析:出站的车厢满足后进先出的关系,所以我们考虑采用栈s 假设车厢一共有n节,n = 5: 进站顺序A:1 ...

  9. K8s存储卷、pv和pvc的使用

    emptyDIR 临时目录 hostPath :使用主机的路径 网络存储: 传统的设备存储:NAS,SAN 分布式存储:glusterfs,rbd,cephfs 云存储:EBS,Azure,阿里云的 ...

  10. Windows下nginx下安装amqp

    1.复制php_amqp.dll 到php/ext/ 2.复制rabbitmq.4.dll 到php/3.复制rabbitmq.4.dll 到windows/system32/ (如32位) ,64位 ...