zoukankan      html  css  js  c++  java
  • selenium登录界面,创建表单并填写提交

    #! python3

    # -*- coding:utf8 -*-

    # https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webdriver.WebDriver.switch_to_frame

    #自动提交表单

     

    from selenium import webdriver

    import time  

    import openpyxl

     

    #读取Excel数据

    wb=openpyxl.load_workbook('E:\work\newFile.xlsx')

    sheet=wb.get_sheet_by_name('Sheet')

    max_rowss=sheet.max_row

    datass=[[] for i in range(max_rowss-1)]

    n=0

    for i in range(2,max_rowss+1):

        if sheet.cell(row=i,column=1).value == None:

            break

        n+=1

        for j in range(1,7):

            datass[n-1].append(sheet.cell(row=i,column=j).value)

            print(sheet.cell(row=i,column=j).value)   

        print('******row %d is done*******' % (n) )

        #打开浏览器

    bs=webdriver.Chrome('C:Program Files (x86)GoogleChromeApplicationchromedriver')

    bs.get('http://172.18.135.40:8081/auth/login')

     

    a=bs.find_element_by_name("usr_name")

    b=bs.find_element_by_name("password")

     

    a.send_keys('usrname')

    b.send_keys('pswd')

    #跳转登录

    b.submit()

    #c=bs.find_element_by_xpath("//input[@type='submit']")

    #c.click()

    #转至默认内容

    time.sleep(1)

    bs.switch_to_default_content()

    c=bs.find_element_by_link_text(u"产品分类")

    c.click()

    time.sleep(1)

    d=bs.find_elements_by_xpath("/html/body/section/div/div/iframe[@frameborder='0']")

    #转至第一个#document

    bs.switch_to_frame(d[1])

    e=bs.find_element_by_xpath("/html/body/div/div/div/span/a[@class='btn btn-primary radius']")

    #点击‘创建接口’

    e.click()

    #转至第二个#document

    time.sleep(2)

    bs.switch_to_frame("layui-layer-iframe1")

    ee=bs.find_elements_by_id("tab_demo")

    ff=ee[0].find_elements_by_xpath("./div")

    #ff中包含6个元素,包含对应模块中的内容信息,依次为 导航菜单,基本信息,字典参数,业务入参,规则代码,变动说明

    f=ee[0].find_elements_by_xpath("./div/span")

    #f中包含5个元素,点击可切换界面 。依次分别是菜单栏上的 基本信息,字典参数,业务入参,规则代码,变动说明

    #切换至 字典参数 界面

    f[1].click()

    time.sleep(1)

    #查找添加按钮

    ffg=ff[2].find_elements_by_xpath("./div/a/i")

    for j in range(n):

        #添加一行表格

        ffg[0].click()

    #查找表格的行,lineNm中第二个tr为第一行填充格。

    lineNm=ff[2].find_elements_by_xpath("./div/table/tbody/tr")

    print(len(lineNm)-1,' lines has created! ')

    def ifNull(val):

        if val==None:

            return ''

        else:

            return val

    print('datass: ',len(datass)  ) 

        for j in range(n):

        ffh=lineNm[j+1].find_elements_by_xpath("./td/input")

        #print("line's length is : ",len(ffh))

        for i in range(6):

            ffh[i].send_keys(ifNull(datass[j][i]))       

    print("game is over!")

  • 相关阅读:
    scala中的注解
    scala中的表达式
    scala中枚举
    spark sql建表的异常
    hive和sequoiadb对接的问题
    java IO的总结
    Spark的序列化
    pentaho和spark-sql对接
    英语口语练习系列-C28-海滨-辨别身份-悬崖边的树
    2018-12-4-今日总结
  • 原文地址:https://www.cnblogs.com/Ting-light/p/9548321.html
Copyright © 2011-2022 走看看