操作日期控件

2018-01-13 11:42:36来源:cnblogs.com作者:sleeping_cat人点击

分享
#!usr/bin/env python  #-*- coding:utf-8 -*-  """ @author:   sleeping_cat@Contact : zwy24zwy@163.com """ #操作日期控件from selenium import webdriverimport unittest,time,tracebackfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support import expected_conditions as ECfrom selenium.common.exceptions import TimeoutException,NoSuchElementExceptionclass TestDemo(unittest.TestCase):    def setUp(self):        self.driver = webdriver.Chrome()    def test_datePicker(self):        url = 'http://jqueryui.com/resources/demos/datepicker/other-months.html'        self.driver.get(url)        time.sleep(3)        try:            wait = WebDriverWait(self.driver,10,0.2)            wait.until(EC.element_to_be_clickable((By.ID,'datepicker')))        except TimeoutException as e:            print(traceback.print_exc())        except NoSuchElementException as e:            print(traceback.print_exc())        except Exception as e:            print(traceback.print_exc())        else:            dateInputBox = self.driver.find_element_by_id('datepicker')            dateInputBox.send_keys('11/24/2016')            time.sleep(3)    def tearDown(self):        self.driver.quit()if __name__ == '__main__':    unittest.main()
注意:该被测网址的日期控件支持输入,但有时会遇到日期选择控件不允许用户输入的情况,此种情况可通过JavaScript语句改变页面元素属性值的方式将日期控件修改成可编辑状态,以便完成脚本直接输入日期来进行日期选择。

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台