zoukankan      html  css  js  c++  java
  • Page--PageLogin

    from selenium.webdriver.common.by import By
    from selenium import webdriver
    import time,os
    from cwp.Page.PageBoard import PageBoard



    class PageLogin():
    #浏览器定义
    def __init__(self,driver = None):
    if driver is None:
    os.system('taskkill /im chromedriver.exe /F')
    self.driver = webdriver.Chrome()
    else:
    self.driver = driver

    # 定义元素
    username_loc = (By.ID,'username')
    password_loc = (By.ID,'password')
    yanzhengma_loc = (By.ID,'verifyCode')
    btn_loc = (By.XPATH,'id("formwrap")/tbody[1]/tr[1]/td[2]/table[1]/tbody[1]/tr[1]/td[2]/table[1]/tbody[1]/tr[13]/td[1]/table[1]/tbody[1]/tr[1]/td[2]/a[1]')

    #定义登录操作
    def login(self,username,password,yanzhengma):
    #("taskkill /im chromedriver.exe /f")
    self.driver.get(url)
    time.sleep(2)
    self.driver.find_element(*self.username_loc).send_keys(username)
    time.sleep(1)
    self.driver.find_element(*self.password_loc).send_keys(password)
    time.sleep(1)
    self.driver.find_element(*self.yanzhengma_loc).send_keys(yanzhengma)
    time.sleep(1)
    self.driver.find_element(*self.btn_loc).click()
    time.sleep(1)
    #ele = self.driver.find_element_by_xpath('id("mainTab")/div[1]/div[3]/ul[1]/li[1]').text
    #self.assertEqual("首页",ele)
            return PageBoard(self.driver)



    if __name__=="__main__":
    pagelogin = PageLogin()
    pagelogin.login('admin','123','1024') #传入登录参数
  • 相关阅读:
    8.26 Linux的目录机构与目录管理
    8.26 基础命令
    8.26 系统基础
    8.26 课程介绍
    8.21-23 awk
    8.20 数组与字符
    8.19 函数
    8.16 sed命令
    Linux操作系统--初级--Linux的目录结构与目录管理
    Linux操作系统--初级--基础命令
  • 原文地址:https://www.cnblogs.com/wenjing2019/p/12102300.html
Copyright © 2011-2022 走看看