场景

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

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

代码

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

#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. linux centos 中访问linux 共享文件方法

    mount -t cifs -o username="administrator",password="" //192.168.1.101/cp /mnt/nt ...

  2. flask+redis实现抢购(秒杀)功能

    今天面试了 一家非常高大上的公司,问了我关于redis的实用性问题,但是答的不是很好,所以下午通过再次学习 redis,实现相关实用性功能的一种. 对于抢购功能,难点在于 抢购时 由于高并发请求,导致 ...

  3. this 指向详细解析(箭头函数)

    前言 this 指向问题是入坑前端必须了解知识点,现在迎来了ES6时代,因为箭头函数的出现,所以感觉有必要对 this 问题梳理一下,遂有此文 在非箭头函数下, this 指向调用其所在函数的对象,而 ...

  4. LeetCode 24. Swap Nodes in Pairs 成对交换节点 C++/Java

    Given a linked list, swap every two adjacent nodes and return its head. You may not modify the value ...

  5. 关于Hibernate和Strtus2的xml提示问题

    话不多说,上图 1.Windom 2.preferences 3.搜索框搜索xml catalog 点击Add 4.导入约束(具体操作图上1.2.3)

  6. Handle/Looper源码分析;

    1. Handle中的属性: final Looper mLooper; final MessageQueue mQueue; final Callback mCallback; final bool ...

  7. idea搭建ssm框架

    1.file-->new-->project-->maven.... 2.建立后的目录: 3.pom.xml依赖建立: <?xml version="1.0" ...

  8. Android中四大组件总结

    android四大组件分别为activity.service.content provider.broadcast receiver. 一.android四大组件详解 1.activity (1)一个 ...

  9. ARM-start.s注释(2410Init.s)

    本人只是做个笔记保存一下. 来源:http://blog.itpub.net/13771794/viewspace-478463/ ;================================= ...

  10. django项目部署

    1.布署前需要关闭调试.允许任何机器访问,在setting文件中设置 DEBUG = False ALLOW_HOSTS=['*',] 2.安装uWSGI pip install uwsgi 3.配置 ...