python爬取下拉列表数据_Python+selenium之获取文本值和下拉框选择数据
Python+selenium之獲取文本值和下拉框選擇數(shù)據(jù)
一、結(jié)合實例進行描述
1. 實例如下所示:
#新增標(biāo)簽操作
def func_labels(self):
self.driver.find_element_by_xpath("//*[@class='menu-text'][text()='業(yè)務(wù)管理']").click()
time.sleep(1)
self.driver.find_element_by_xpath("//*[@class='menu-text'][text()='打標(biāo)簽']").click()
time.sleep(1)
self.driver.find_element_by_id("btn-addTag").click()#點擊【新增標(biāo)簽】按鈕
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來下拉選擇數(shù)據(jù)(隱藏屬性)
#time.sleep(1)
self.driver.execute_script("$('#tag_senderId option:eq(1)').attr('selected',true).change()")#下拉框選中發(fā)貨方
#time.sleep(1)
self.driver.find_element_by_id('tag_totalCnt').send_keys(3)#填寫貨品件數(shù)
#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)#填寫數(shù)量值
#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來獲取內(nèi)容值
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來下拉選擇數(shù)據(jù)(隱藏屬性)
②在層級菜單中,一定需要加上一個延時,這里以time.sleep(2)為例,否則,會報錯
③ls=self.driver.execute_script('return $("#hid_new_tagno").text();')#使用return返回值,運用JS來獲取內(nèi)容值
總結(jié)
以上是生活随笔為你收集整理的python爬取下拉列表数据_Python+selenium之获取文本值和下拉框选择数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: tensorflow包_在Keras和T
- 下一篇: python fpga_如何实现用Pyt