python爬取下拉列表数据_Python+selenium之获取文本值和下拉框选择数据

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

一、结合实例进行描述

1. 实例如下所示:

#新增标签操作

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来获取内容值

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值