用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领取奖励 目标:连续四天自动运行脚本,自动领取所 ...
随机推荐
- N 皇后问题
#include <set> #include <iostream> #include <string> #include <vector> #incl ...
- react参考项目001
https://github.com/chen2009277025/webpack-ant-design-demo https://github.com/cobish/cobish.github.io ...
- batchInsert xml 配置 ibatis
<insert id="tops_visa_openapi_jvisaproduct.batchinsert" parameterClass="java.util. ...
- wxPython入门练习代码 二
WxPython书籍[摘记] 1.任何wxPython应用程序都需要一个应用程序对象.这个应用程序对象必须是类wx.App或其定制的子类的一个实例.2.在OnInit()方法中将至少创建一个框架对象, ...
- 满足NABC的软件创意
创意——几个简单的想法 ——崔海营 创意一: 大学生自行车租借一点通 随着大学生人数的不断增多以及大学生活的空闲时间十分充裕,许多同学十分乐意到一些附近的景点去游玩或者烧烤 ...
- elasticsearch相关文章
http://blog.csdn.net/laigood12345/article/category/1113868
- myeclipse激活法,可以试一试
我的myeclipse2014也是这样激活: 第一步:输入任意用户名 第二步:点击Systemid... 按钮,自动生成本机器的systemid. 第三步: 点菜单Tools->RebuildK ...
- Android Fragment (一)
1.Fragment的产生与介绍 Android运行在各种各样的设备中,有小屏幕的手机,超大屏的平板甚至电视.针对屏幕尺寸的差距,很多情况下,都是先针对手机开发一套App,然后拷贝一份,修改布局以 ...
- javaScript学习(入门)
不落俗套的来讲讲javascript的特点: 1.所有主流浏览器都是支持javascript的. 2.绝大部分网页都使用javascript. 3.javascript可以实现网页呈现各种动态效果. ...
- shell 简单的比大小脚本
#!/bin/bash echo "第一个数字" read a echo "第二个数字" read b if [ $a -gt $b ] then echo & ...