python+selenium UI脚本用例

1.最近在用公司的一个工具拉取一些业务数据时发现有很多重复的页面操作,每次都要重复的选择机构与对应的表,点击添加操作(十几家机构加起来要手工添加两百多次),于是用python写了一个UI脚本让机器去执行这些重复的操作,即省时效率又高。

#coding:utf8
from selenium import webdriver
from config.params import *
from selenium.webdriver.support.ui import Select
import time

class pullData():

path="E:/chromedriver.exe"

def __init__(self,url):
    self.url=url
    self.wd = webdriver.Chrome(self.path)

def openBrowser(self):
    self.wd.get(self.url)
    self.wd.maximize_window()

def closeBrowser(self):
    self.wd.quit()

def findeleOrg(self):
    hospitals = self.wd.find_elements_by_css_selector("select[name=‘hospitalCode‘]>option")
    return hospitals

def findeledept(self):
    hospitalDatatype = self.wd.find_elements_by_css_selector(‘select[name$="DataType"]>option‘)
    return hospitalDatatype

def deleteCords(self):
    while True:
        cords=self.wd.find_elements_by_css_selector("table[border=‘1‘] tr>td:nth-of-type(8)>input[value=‘删除‘]")
        if len(cords)==0:
            break
        cords[0].click()
        time.sleep(1)    #定位元素前后要加等待时间,特别是刷新的页面

def hospitalConfig(self):

    self.wd.find_element_by_partial_link_text(u"医院视图SQL").click()
    hospitals=self.findeleOrg()
    hospitalDatatype=self.findeledept()

    for num in range(len(hospitals)-1):
        hospitals = self.findeleOrg()
        hospitals[num].click()

        for numdata in range(len(hospitalDatatype)-1):
            hospitals = self.findeleOrg()
            hospitals[num].click()
            hospitalDatatype = self.findeledept()
            time.sleep(1)
            hospitalDatatype[numdata].click()
            time.sleep(2)
            self.wd.find_element_by_css_selector("input[type=‘submit‘]").click()
            self.wd.find_element_by_id("submit_id").click()
            self.wd.find_element_by_partial_link_text(u"医院视图SQL").click()

if name=="main":
pullD = pullData(url)
pullD.openBrowser()
pullD.hospitalConfig()
pullD.deleteCords()

原文地址:http://blog.51cto.com/13599360/2091355

时间: 2024-08-01 09:58:33

python+selenium UI脚本用例的相关文章

Python+selenium(11)脚本模块化&参数化

mail126.py脚本如下 from selenium import webdriver from time import sleep from model1 import Login driver = webdriver.Chrome() driver.get("http://www.126.com") print("登录前") title = driver.title print("title:" + title) #调用登录 l = Lo

python+selenium+Robot

准备工作: 1.下载python2.7 http://python.org/getit/ 2.下载下载setuptools [python 的基础包工具] 可以帮助我们轻松的下载,构建,安装,升级,卸载python的软件包. http://pypi.python.org/pypi/setuptools 3.下载pip[python 的安装包管理工具] 有了这个工具,我们只需要一个命令就可以轻松的python的安装任意类库. https://pypi.python.org/pypi/pip 4.解

【Mac + Python + Selenium】之获取验证码图片code并进行登录

初稿代码,可以忽略不计(自己留着看) #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2020/01/15 13:27 # @Author : zc # @File : 115test.py from selenium import webdriver from selenium.webdriver.common.by import By from time import sleep from PIL import Image,Im

利用Python的unittest单元测试框架的discover方法批量执行脚本用例

1.在用Python自动化时,执行单个脚本用例那都是so easying当脚本用例不断地增多时,那就蒙蔽了,一个个来跑到什么时候才跑完,所以discover方法作用就出来,废话不多,小编直接上代码了,如有疑问,可以咨询小编 #!/usr/bin/python# -*- coding: utf-8 -*-from selenium import webdriverimport time,osfrom selenium.webdriver.common.action_chains import Ac

Python+Selenium搭建UI自动化测试框架

Python语言是非常强大的编程语言,很多时候也拿来当脚本语言用. Selenium是web应用测试工具,支持Java.Python等多种语言脚本,支持Chrome.Firefox等多种主流浏览器.主要实现的就是模拟人使用web应用,自动的打开浏览器.打开应用.进入应用进行各种模拟业务操作等等. 接下来,一步一步带领大家实现下Python+Selenium实现使用脚本自动发微博的功能. 1.Python安装 一般Linux系统自带了Python,Windows系统可以参考本人之前文章 [Pyth

快速低成本在新浪云SAE上建立定时执行任务 -以python脚本为例

1解决的问题和优势 l 利用SAE云应用不间断在线的特点,支持定时执行任务,支持php.java.python2.7等语言运行,从此不用担心自己的电脑关机了,没网络了不能及时有效运行定时任务的尴尬,当然也可以部署其他自己或SAE提供的应用(收费了,与其他云平台区别不大) l 对于一些小脚本的定时运行基本可以做到免费,代码空间5G,存储空间10G,可以支持小爬虫定时采集网页,自动发微博,帖子等各种有趣的功能 l 使用较为简单,上手容易,文档帮助齐全,可以快速使用 2 建立自己的定时运行应用 ...

豆瓣自动注册、回贴脚本 powered by Python & Selenium

前言,之前在豆瓣日志写了这片文章,结果被豆瓣删除了...哎 ----- 所删除内容 ----- <豆瓣自动注册.回贴脚本 powered by Python & Selenium> (2018-01-12 15:29) 故事起因: 上周的时候吧,发现有条疯狗在这张剧照(天生杀人狂)下面骂我.如果只是骂我傻逼我还能忍,毕竟人在江湖飘哪人不挨刀.但是你问候的范围大了,那作为一个社会主义核心价值观没有问题的青年,我必须得去操一下你妈了吧.请点击操他妈热线.结果这个怂逼居然还发私信骂我然后还把

Python Selenium 搭建Web UI自动化

Python搭建UI自动化环境 下载Python3 Python官网 PyCharm 环境配置 安装Python 勾选Add Python to PATH,一直下一步. 验证:CMD输入Python 下载Chrome Driver 点击下载chromedriver 将驱动放入Python根目录下 安装PyCharm 转载:安装教程 安装Selenium 打开PyCharm 新建Python File 点击面板底部 Terminal 输入pip install selenium 安装.pip li

转 Python Selenium设计模式-POM

前言 本文就python selenium自动化测试实践中所需要的POM设计模式进行分享,以便大家在实践中对POM的特点.应用场景和核心思想有一定的理解和掌握. 为什么要用POM 基于python selenium2开始UI级自动化测试并不是多么艰巨的任务.只需要定位到元素,执行对应的操作即可.下面我们看一下这个简单的脚本实现百度搜索. from selenium import webdriver import time driver = webdriver.Firefox() driver.i