用python+selenium登录cnblog后新增文章后再次删除该文章
目的:登录cnblog后新增文章后再次删除该文章并验证
代码如下:
#coding: utf-8
from selenium import webdriver
from time import sleep
import unittest
import time class DeletePost(unittest.TestCase): def setUp(self):
self.dr = webdriver.Chrome()
self.dr.maximize_window() #定义登录方法
def login(self, username, password):
self.dr.get('https://passport.cnblogs.com/user/signin') #cnblog登录页面
self.dr.find_element_by_id('input1').send_keys(username)
self.dr.find_element_by_id('input2').send_keys(password)
self.dr.find_element_by_id('signin').click() #定义新增文章方法
def create_post(self, title, content):
self.dr.get('https://i.cnblogs.com/EditPosts.aspx?opt=1') #cnblog新增文章页面
self.dr.find_element_by_id('Editor_Edit_txbTitle').send_keys(title)
self.set_content(content)
self.dr.find_element_by_id('Editor_Edit_lkbPost').click() #定义输入富文本content方法
def set_content(self, content):
js = 'document.getElementById("Editor_Edit_EditorBody_ifr").contentWindow.document.body.innerHTML=\'%s\'' % (content)
self.dr.execute_script(js) #定义获取文章post-id方法
def create_post_and_return_its_id(self, title, content):
self.create_post(title, content)
tokens = self.dr.find_element_by_css_selector('#TipsPanel_LinkEdit').get_attribute('href').split('=')
return tokens[-1] #所有文章都对应唯一的post-id #验证删除新增的文章
def test_delete_post_success(self):
'''验证删除新增加的Post'''
self.login('kemi_xxxx', 'kemi_xxxx') #cnblog帐号密码
title = 'title %s' %(time.time()) #标题为title和当前时间
content = 'content %s' %(time.time()) #内容为content和当前时间
sleep(5)
post_id = self.create_post_and_return_its_id(title, content) #调用post-id方法并获得相应id
self.dr.get('https://i.cnblogs.com/') #cnblog后台管理页面
row_id = 'post-row-' + post_id #定义文章列表的行id
post = self.dr.find_element_by_id(row_id) #定位到相应行id上
post.find_element_by_xpath("//a[@href='javascript:void(0)']").click() #定位删除并点击
self.dr.switch_to_alert().accept() #点击弹窗中的确定
sleep(2)
post.find_element_by_xpath("//span[@style='color:red']") #定位相应post的删除成功!提示 def tearDown(self):
print('测试完毕!')
self.dr.quit() if __name__ == '__main__':
unittest.main()
效果如下:

用python+selenium登录cnblog后新增文章后再次删除该文章的更多相关文章
- 一次完整的自动化登录测试-基于python+selenium进行cnblog的自动化登录测试
Web登录测试是很常见的测试!手动测试大家再熟悉不过了,那如何进行自动化登录测试呢!本文作者就用python+selenium结合unittest单元测试框架来进行一次简单但比较完整的cnblog自动 ...
- 一次简单完整的自动化登录测试-基于python+selenium进行cnblog的自动化登录测试
Web登录测试是很常见的测试,手动测试大家再熟悉不过了,那如何进行自动化登录测试呢!本文就基于python+selenium结合unittest单元测试框架来进行一次简单但比较完整的cnblog自动化 ...
- Python+selenium登录测试
我们以登录新浪微博为案例来讲解,首先进入登录页面,输入用户名和密码,点击登录按钮,并且获得用户信息以验证是否登录成功. Web地址:https://login.sina.com.cn/signup/s ...
- Python selenium登录163邮箱示例
思路:使用python自带的unittest单元测试框架测试163邮箱登录成功的case import unittestfrom selenium import webdriverimport tim ...
- python+selenium运行时,提示元素不可见
python+selenium运行多次新增项目脚本(出错的元素通过by_id的方式定位),当第三次新增时报Message: element not visible的错误,加入等待时间,等页面加载完成, ...
- Python + Selenium 实现登录Office 365
最近捡起之前用的Python + Selenium实现工作中需要的登录Office 365功能.(吐槽:国内网络真是卡,登录Office 365实属不易.另外Selenium这样的网站都要墙,无法理解 ...
- Python Selenium Cookie 绕过验证码实现登录
Python Selenium Cookie 绕过验证码实现登录 之前介绍过博客园的通过cookie 绕过验证码实现登录的方法.这里并不多余,会增加分析和另外一种方法实现登录. 1.思路介绍 1.1. ...
- python RSA加密解密及模拟登录cnblog
1.公开密钥加密 又称非对称加密,需要一对密钥,一个是私人密钥,另一个则是公开密钥.公钥加密的只能私钥解密,用于加密客户上传数据.私钥加密的数据,公钥可以解密,主要用于数字签名.详细介绍可参见维基百科 ...
- python+selenium自动化登录dnf11周年活动界面领取奖励登录部分采坑总结[1]
背景: Dnf的周年庆活动之一,游戏在6月22日 06:00~6月23日 06:00之间登陆过游戏后可以于6月25日 16:00~7月04日 06:00领取奖励 目标:连续四天自动运行脚本,自动领取所 ...
随机推荐
- curl --connect-timeout 判断国内外网络windows 批处理
1.下载编译curl curl 下载地址:http://curl.haxx.se/download.html ,下载后解压到一个目录,使用vs开发者工具里的 “Visual Studio 命令提示(2 ...
- cron表达式使用详解
Cron表达式是一个字符串,字符串以5或6个空格隔开,分为6或7个域,每一个域代表一个含义,Cron有如下两种语法格式: Seconds Minutes Hours DayofMonth Month ...
- 【Python②】python之首秀
第一个python程序 再次说明:后面所有代码均为Python 3.3.2版本(运行环境:Windows7)编写. 安装配置好python后,我们先来写第一个python程序.打开IDLE (P ...
- 更新证书错误:No matching provisioning profiles found
在Xcode中当你在更新了你得证书而再重新编译你的程序,真机调试会出现“Your build settings specify a provisioning profile with the UUID ...
- TRANSPOSE的DATA步实现
data a; input name $ a b ; cards; x x x y y y ; run; %macro transpose; proc sql noprint ; select cou ...
- myeclipse 快捷键大全
转自:http://q.cnblogs.com/q/47190/ Technorati 标记: Shortcut keys Ctrl+1 快速修复(最经典的快捷键,就不用多说了)Ctrl+D: 删除当 ...
- S3C6410开发板开发环境的搭建
本节主要介绍了S3C6410开发板及OK6410开发板.OK6410开发板是基于ARM11处理器的S3C6410,采用“核心版+底板”结构 主要步骤如下:. OK6410开发板自带一个串口,PC也需要 ...
- store前台数据过滤
最近由于客户需要对grid进行大量的检索操作,而现有的grid数据是以分页的形式从数据库端获取,每次检索都需要重新进行获取,效率很低. 因而将数据进行一次加载,每次的检索操作在前台extjs进行过滤, ...
- hongxin
邀请链接 :http://honx.in/_VbiG2CZDjwIE8l1t
- IOS UITableView移除底部空白行
tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];