首页 > 编程语言 >python中selenium封装

python中selenium封装

时间:2024-06-18 20:33:14浏览次数:12  
标签:封装 python self selenium element click time id find

from selenium import webdriver
import time
class cms(object):
a = webdriver.Chrome()
def init(self):
self.a.get("http://192.168.193.135:8080/cms/manage/login.do")
time.sleep(2)
self.a.find_element_by_name("userAccount").send_keys("admin")
time.sleep(2)
self.a.find_element_by_id("loginPwd").send_keys("123456")
time.sleep(2)
self.a.find_element_by_name("online").click()
time.sleep(2)
self.a.find_element_by_xpath('//[@id="loginBtn"]').click()
self.a.maximize_window()
time.sleep(2)
def exit(self):
self.a.find_element_by_link_text("退出").click()
def cx(self):
self.a.find_element_by_xpath('//
[@id="menu-user"]/dt').click()
time.sleep(2)
self.a.find_element_by_link_text("用户管理").click()
b=self.a.find_element_by_xpath('//[@id="iframe_box"]/div[2]/iframe')
self.a.switch_to.frame(b)#进入iframe页
time.sleep(2)
self.a.find_element_by_id("searchValue").send_keys("222")
self.a.find_element_by_name("searchBtn").click()#点击
time.sleep(2)
self.a.find_element_by_xpath('/html/body/nav/a').click()#刷新
def create(self):
self.a.find_element_by_xpath('//
[@id="menu-user"]/dt').click()
time.sleep(2)
self.a.find_element_by_link_text("用户管理").click()
b=self.a.find_element_by_xpath('//[@id="iframe_box"]/div[2]/iframe')
self.a.switch_to.frame(b)#进入iframe页
self.a.find_element_by_link_text("添加用户").click()
time.sleep(2)
c=self.a.find_element_by_xpath('//
[@id="xubox_iframe1"]')
self.a.switch_to.frame(c)
time.sleep(2)
self.a.find_element_by_name("userName").send_keys("fss")
self.a.find_element_by_xpath('//[@id="userSex"]').click()
self.a.find_element_by_xpath('//
[@id="userSex"]').click()
self.a.find_element_by_name("userMobile").send_keys("13154818951")
self.a.find_element_by_name("userEmail").send_keys("[email protected]")
self.a.find_element_by_name("userAccount").send_keys("fss")
self.a.find_element_by_name("loginPwd").send_keys("1315481895")
self.a.find_element_by_name("confirmPwd").send_keys("1315481895")
self.a.find_element_by_xpath('//[@id="submitBtn"]').click()
def qt(self):
self.a.find_element_by_xpath('//
[@id="menu-user"]/dt').click()
time.sleep(2)
self.a.find_element_by_link_text("用户管理").click()
b=self.a.find_element_by_xpath('//[@id="iframe_box"]/div[2]/iframe')
self.a.switch_to.frame(b)#进入iframe页
time.sleep(2)
self.a.find_element_by_xpath('//
[@id="sysUserTab"]/tr[1]/td[9]/a[1]').click()
time.sleep(2)
self.a.find_element_by_xpath('//*[@id="xubox_layer1"]/div[1]/span[2]/a[1]').click()

if name == 'main':
b=cms()
# b.login()
# b.exit()
b.qt()

标签:封装,python,self,selenium,element,click,time,id,find
From: https://www.cnblogs.com/fanshsh/p/18255068

相关文章

  • 【Python数据分析】Pandas_描述性统计
    描述统计学(descriptivestatistics)是一门统计学领域的学科,主要研究如何取得反映客观现象的数据,并以图表形式对所搜集的数据进行处理和显示,最终对数据的规律、特征做出综合性的描述分析。Pandas库正是对描述统计学知识完美应用的体现,可以说如果没有“描述统计学”作为理论基......
  • 在现代编程环境中,Perl 如何与其他流行语言(如 Python、Java 等)进行集成和协作?
    在现代编程环境中,Perl可以与其他流行语言(如Python、Java等)进行集成和协作。以下是一些常见的方法:调用外部程序:Perl可以使用系统调用来执行其他语言编写的可执行文件。这意味着可以从Perl中调用Python、Java等程序,并将它们的输出捕获到Perl程序中进行处理。使......
  • python系列&AI系列:cannot import name ‘ForkProcess‘ from ‘multiprocessing.conte
    cannotimportname‘ForkProcess‘from‘multiprocessing.context‘问题解决cannotimportname‘ForkProcess‘from‘multiprocessing.context‘问题解决问题描述问题原因解决方案cannotimportname‘ForkProcess‘from‘multiprocessing.context‘问......
  • python系列:使用Python快速读取PDF中的表单数据以及error处理
    使用Python快速读取PDF中的表单数据以及error处理使用Python快速读取PDF中的表单数据安装PythonPDF库Python读取PDF表单数据1、一次性读取多种PDF表单的数据2、读取特定PDF表单的数据python读取PDF文件中文本、表格、图片python读取PDF文件中文本、表格、图片一、文本......
  • python系列:[Python]在VSCode中搭建Python开发环境
    [Python]在VSCode中搭建Python开发环境[Python]在VSCode中搭建Python开发环境前言安装1.安装VSCode的Python插件2.选择python解释器3.运行代码配置python检查项安装对应的库修改vscode的配置文件[Python]在VSCode中搭建Python开发环境前言之前用过Anaconda......
  • centos7 安装 python3.12
    准备工作yuminstallcentos-release-sclsclenabledevtoolset-11bashwgethttps://www.python.org/ftp/python/3.12.4/Python-3.12.4.tgz编译注意是在scl环境下进行的,gcc版本过低的环境会导致编译失败tar-zxfPython-3.12.4.tgzcdPython-3.12.4./configure--pr......
  • python文件操作、文件操作、读写文件、写模式
    with读取文件数据内容withopen(filepath,mode,encoding)asfile:#具体操作,例如:print(file.read())#查看文件所有的内容。with:Python中的一个上下文管理器,用于简化资源的管理和释放。它可以用于任意需要进行资源分配和释放的情境,比如文件操作、数据库连......
  • Win11+Miniconda3+python3.9安装pyspark+pytorch
    Win11+Miniconda3+python3.9安装pyspark+pytorch步骤1:安装Miniconda3,具体可以百度或者google步骤2:安装好Miniconda3之后,要创建虚拟环境,类似于虚拟机的样子,然后在虚拟环境安装各种python包已经装好了pytorch,具体步骤可以参考网上的一些教程,很多时候要综合多个教程,比如说先建立......
  • python 注册nacos 进行接口规范定义
    背景:一般场景python服务经常作为java下游的算法服务或者数据处理服务但是使用http去调用比较不灵活,通过注册到nacos上进行微服务调用才是比较爽的1.定义feginapi的接口定义java端定义接口请求和响应主要关注CommonResult结构和python要一直,不然序列号是有问题的Co......
  • Python编程基础:f-字符串格式
    本文探讨使用Pythonf-字符串格式,也称为“格式化字符串文字”。f-string是格式化字符串的一种很好且简单的方法,适用于Pythonv3.6+。如果你仍然使用.format()方法,必须了解f-字符串。使用字符串格式的优势之一是能够“插入”并格式化字符串数据中的变量。Python字符串format()方......