用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领取奖励 目标:连续四天自动运行脚本,自动领取所 ...
随机推荐
- 【仿真】Lattice_Diamond_调用Modelsim_仿真
仿真前的准备工作:在modelsim中添加lattice仿真库:1.去除modelsim安装目录下modelsim.ini的只读属性.2.打开modelsim,更改目录File>Change d ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E. Goods transportation (非官方贪心解法)
题目链接:http://codeforces.com/contest/724/problem/E 题目大意: 有n个城市,每个城市有pi件商品,最多能出售si件商品,对于任意一队城市i,j,其中i&l ...
- 说一说windows原生docker及windows Server Container , Hyper Container 之间的关系(学习总结)
前一段时间学习netcore的时候解除到了docker,感觉真是不错的技术.百度了不少教程.因为我用windows就下载安装了一下试试.但是没有安装成功,才发现 需要安装virtualbox虚拟机,与 ...
- React Native 组件样式测试
View组件默认样式(注意默认flexDirection:'column') {flexGrow:0,flexShrink:0,flexBasis:'auto',flexDirection:'colu ...
- uboot mmc烧写命令
mmc write addr blk# cnt 这个命令的作用是将内存上的数据写入mmc中 参数: addr: 从内存读取的位置 blk: 写入到mmc中block位置,这个位置是mmc的0地址的偏移 ...
- [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys
错误原因在于出现相同内容. 原写为: <li ng-repeat="log in logs" scroll-down> {{log}}</li> 改写为: ...
- 在VBA中调用excel函数
以前不太会用VBA时,都是在excel中使用函数来计算一些数据.毕竟函数不如代码,效率比较低.所以,就学着怎么在VBA中引用Excel函数.平时我用得比较多的函数就是countif和sumif函数.1 ...
- JS在火狐浏览器下如何关闭标签?
首先,要确定火狐设置是否允许通过JS代码window.close()方法关闭标签. 确定方式如下: 在Firefox地址栏里输入 about:config 在配置列表中找到dom.allow_scri ...
- 虚机centos和本机Windows之间文件的拷贝无法用xftp时用FileZilla也行
步骤如下: 1.如果Centos没有安装ssh,则需要先安装: 2.查看虚拟机中IP地址,命令如下: ifconfig 3.在windows中安装ftp软件 FileZilla启动软件如图: 6 这 ...
- 好文mark
用oracle的dblink连接mysql. http://f.dataguru.cn/thread-267150-1-1.html hadoop的机架感知: 本地化策略,以及备份都要知道哪个节点在哪 ...