美文网首页
界面自动化脚本示例(一)

界面自动化脚本示例(一)

作者: Kingtester | 来源:发表于2019-08-07 16:40 被阅读0次
    from  selenium import webdriver
    from selenium.webdriver.support.select import Select
    
    from selenium.webdriver.common.keys import Keys
    import time
    import csv
    import sys
    import datetime
    import os
    
    with open(r'D:\wenjian\data_zhz.csv') as csvfile:   
        readCSV = csv.reader(csvfile, delimiter=',')        #readCSV读取的是这个文件的每一竖列数据               
        yhms=[]                                                               #定义空数组
        mms=[]
        dzyxs=[]
        xms=[]
        zjhms=[]
        sjs=[]
        xxdzs=[]
        zgxls=[]
        cyzks=[]
        for row in readCSV:
            yhm=row[0]                                                            #每一列命名
            mm=row[1]
            dzyx=row[2]
            xm=row[3]
            zjhm=row[4]
            sj=row[5]
            xxdz=row[6]
            zgxl=row[7]
            cyzk=row[8]
            yhms.append(yhm)                                         #将每一列的数据装入到空白的数组中
            mms.append(mm)
            dzyxs.append(dzyx)
            xms.append(xm)
            zjhms.append(zjhm)
            sjs.append(sj)
            xxdzs.append(xxdz)
            zgxls.append(zgxl)
            cyzks.append(cyzk)
    n=len(yhms)                                                             #需要知道总共CSV文件有多少行
    driver = webdriver.Chrome()
    for i in range(1842,n):
        yh=yhms[i]                                                                           
        m=mms[i]
        dzy=dzyxs[i]
        x=xms[i]
        zjh=zjhms[i]
        s=sjs[i]
        xxd=xxdzs[i]
        zgx=zgxls[i]
        cyz=cyzks[i]
        time.sleep(2)
        driver.get("https://hb.chinavolunteer.cn/app/user/register.php")
    
        #driver.maximize_window()
        driver.refresh()
        time.sleep(2)
        # 用户名
        yhm_txt = driver.find_element_by_id("login_name").get_attribute("value")
    
        driver.find_element_by_id("login_name").send_keys(yh)
        #time.sleep(1)
        #确定用户名
        qdyhm_txt = driver.find_element_by_id("login_name_repeat").get_attribute("value")
    
        driver.find_element_by_id("login_name_repeat").send_keys(yh)
        #time.sleep(1)
        #密码
        mm_txt = driver.find_element_by_id("login_pass").get_attribute("value")
    
        driver.find_element_by_id("login_pass").send_keys(m)
        #time.sleep(1)
        #确定密码
        qdmm_txt = driver.find_element_by_id("login_pass_repeat").get_attribute("value")
    
        driver.find_element_by_id("login_pass_repeat").send_keys(m)
        #time.sleep(1)
        #电子邮箱
        dzyx_txt = driver.find_element_by_id("login_email").get_attribute("value")
    
        driver.find_element_by_id("login_email").send_keys(dzy)
        #time.sleep(1)
        #确定电子邮箱
        qddzyx_txt = driver.find_element_by_id("login_email_repeat").get_attribute("value")
    
        driver.find_element_by_id("login_email_repeat").send_keys(dzy)
        #time.sleep(1)
        #真实姓名
        zsxm_txt = driver.find_element_by_id("vol_true_name").get_attribute("value")
    
        driver.find_element_by_id("vol_true_name").send_keys(x)
        #time.sleep(2)
        #证件号码
        zjhm_txt = driver.find_element_by_id("vol_cert_number").get_attribute("value")
    
        driver.find_element_by_id("vol_cert_number").send_keys(zjh)
        time.sleep(2)
        #政治面貌
        sell=driver.find_element_by_id("vol_political")                                        #下拉框的选择方法
        Select(sell).select_by_value("4859")
        time.sleep(1)
        #籍贯
        sel=driver.find_element_by_id("nat_district1")
        Select(sel).select_by_value("7385")
        time.sleep(2)
        sel=driver.find_element_by_id("nat_district2")
        Select(sel).select_by_value("7500")
        time.sleep(2)
        sel=driver.find_element_by_id("nat_district3")
        Select(sel).select_by_value("23694")
        time.sleep(1)
        #手机
        sj_txt = driver.find_element_by_id("login_mobile").get_attribute("value")
    
        driver.find_element_by_id("login_mobile").send_keys(s)
        #time.sleep(1)
        #居住区域
        time.sleep(2)
        sel=driver.find_element_by_id("house_district1")
        Select(sel).select_by_value("7500")
        time.sleep(2)
        sel=driver.find_element_by_id("house_district2")
        Select(sel).select_by_value("23694")
        #time.sleep(1)
        #详细地址
        xxdz_txt = driver.find_element_by_id("vol_address").get_attribute("value")
    
        driver.find_element_by_id("vol_address").send_keys(xxd)
        time.sleep(1)
        #学历、从事行业
        sel=driver.find_element_by_id("vol_edu_degree")
        Select(sel).select_by_value("4542")
        time.sleep(1)
        sel=driver.find_element_by_id("vol_job_title")
        Select(sel).select_by_value("23276")
        time.sleep(1)
        #服务区域
        time.sleep(2)
        sel=driver.find_element_by_id("district1")                       
        Select(sel).select_by_value("7500")
        time.sleep(3)
        sel=driver.find_element_by_id("district2")
        Select(sel).select_by_value("23694")
        #time.sleep(2)
        #服务类别
        checkboxes = driver.find_elements_by_css_selector('input[type=checkbox]')              #多选框的选择
        for a in checkboxes:
            if a.get_attribute('value') == '清洁家园':
                a.click()
            elif a.get_attribute('value') == '社区服务':
                a.click()
        #time.sleep(2)
        #服务领域或行业register
        driver.find_element_by_id("stype_23392").click()
        driver.find_element_by_id("stype_23393").click()
        #time.sleep(1)
        driver.find_element_by_link_text("申请成为实名注册志愿者").click()
        time.sleep(1)
        driver.refresh()
    

    相关文章

      网友评论

          本文标题:界面自动化脚本示例(一)

          本文链接:https://www.haomeiwen.com/subject/mycadctx.html