<input id="txtBeginDate" style="170px;padding:7px 10px;border:1px solid #ccc;margin-right:10px;" readonly="">
方法1、直接定位 方法2、移除readonly属性变输入 from selenium import webdriver from time import sleep driver = webdriver.Firefox() driver.get('http://www.sucaijiayuan.com/api/demo.php?url=/demo/20141108-1/') driver.switch_to.frame('iframe') # js = "document.getElementById('txtBeginDate').removeAttribute('readonly')" # 1.原生js,移除属性 # js = "$('input[id=txtBeginDate]').removeAttr('readonly')" # 2.jQuery,移除属性 # js = "$('input[id=txtBeginDate]').attr('readonly',false)" # 3.jQuery,设置为false js = "$('input[id=txtBeginDate]').attr('readonly','')" # 4.jQuery,设置为空(同3) driver.execute_script(js) driver.find_element_by_id('txtBeginDate').send_keys('2016-08-24') sleep(2) print driver.find_element_by_id('txtBeginDate').get_attribute('value') driver.quit()