• Python+selenium之获取文本值和下拉框选择数据


    原文链接地址:https://www.cnblogs.com/Rita-LJ/p/8334526.html

    Python+selenium之获取文本值和下拉框选择数据

    一、结合实例进行描述

    1. 实例如下所示:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    #新增标签操作
       def func_labels(self):
           self.driver.find_element_by_xpath("//*[@class='menu-text'][text()='业务管理']").click()
           time.sleep(1)
           self.driver.find_element_by_xpath("//*[@class='menu-text'][text()='打标签']").click()
           time.sleep(1)
           self.driver.find_element_by_id("btn-addTag").click()#点击【新增标签】按钮
           time.sleep(1)
           self.driver.execute_script("$('#tag_receivingId_flexselect').blur();$('#tag_receivingId option:eq(2)').attr('selected',true).change();ecui.form.flexSelect('#tag_receivingId');")#运用js来下拉选择数据(隐藏属性)
           #time.sleep(1)
           self.driver.execute_script("$('#tag_senderId option:eq(1)').attr('selected',true).change()")#下拉框选中发货方
           #time.sleep(1)
           self.driver.find_element_by_id('tag_totalCnt').send_keys(3)#填写货品件数
           #time.sleep(1)
           self.driver.execute_script("$('#tagDetail_prod option:eq(1)').attr('selected',true).change()")#下拉选择“货品信息”
           #time.sleep(1)
           self.driver.find_element_by_id('tagDetail_prodCount').send_keys(5)#填写数量值
           #time.sleep(1)
           self.driver.find_element_by_xpath("//button[@data-bb-handler='success']").click()#点击【保存】按钮
           #self.driver.find_element_by_xpath("//button[@class='btn btn-purple ehkey-saveAndPrint']").click()#点击【保存并打印】按钮
           # < div
           # id = "hid_new_tagno"
           # style = "display: none" >
           #
           # < / div >
           ls=self.driver.execute_script('return $("#hid_new_tagno").text();')#运用JS来获取内容值
           time.sleep(2)
           # 参考http://blog.csdn.net/eastmount/article/details/48108259
           time.sleep(2)
           self.driver.find_element_by_xpath("//span[@class='menu-text'][text()='托运单']").click()
           time.sleep(1)
           self.driver.find_element_by_xpath("//button[@id='btn-addTag']").click()
           bs=self.driver.find_element_by_id("tag_tagNo")
           bs.send_keys(ls)
           bs.send_keys(Keys.RETURN)#回车
           time.sleep(2)
           self.driver.find_element_by_xpath("//button[@class='btn btn-success ehkey-save']").click()
           self.driver.quit()  

    2.上述代码中:

    ①self.driver.execute_script("$('#tag_receivingId_flexselect').blur();  $('#tag_receivingId option:eq(2)').attr('selected',true).change();  ecui.form.flexSelect('#tag_receivingId');")#运用js来下拉选择数据(隐藏属性)

    ②在层级菜单中,一定需要加上一个延时,这里以time.sleep(2)为例,否则,会报错

    ③ls=self.driver.execute_script('return $("#hid_new_tagno").text();')#使用return返回值,运用JS来获取内容值

  • 相关阅读:
    移动端页面使用rem布局
    Vue2.0 render:h => h(App)
    sublime3 快捷键大全
    node-webkit学习之【无边框窗口用JS实现拖动改变大小等】
    mock.js-无需等待,随机产生数据,让前端独立于后端进行开发
    Sublime Text 3 遇到的一些小坑的解决方法
    Angular Cli 升级到最新版本
    Angular 表单嵌套、动态表单
    angular6 iframe应用
    JS 时间格式 相互转化
  • 原文地址:https://www.cnblogs.com/yimai-series/p/12197623.html
Copyright © 2020-2023  润新知