zoukankan      html  css  js  c++  java
  • 操作日期控件

    #!usr/bin/env python  
    #-*- coding:utf-8 -*-  
    """ 
    @author:   sleeping_cat
    @Contact : zwy24zwy@163.com 
    """ 
    #操作日期控件
    
    from selenium import webdriver
    import unittest,time,traceback
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.common.exceptions import TimeoutException,NoSuchElementException
    
    class 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语句改变页面元素属性值的方式将日期控件修改成可编辑状态,以便完成脚本直接输入日期来进行日期选择。
  • 相关阅读:
    java之 向上转型与向下转型
    java之 惰性初始化
    mysql 学习网站
    history of program atan2(y,x)和pow(x,y)
    atom 之 前端必备插件
    js之正则表达式
    Django之模型层
    每日作业5/28
    每日作业5/27
    每日作业5.26
  • 原文地址:https://www.cnblogs.com/sleeping-cat/p/8278485.html
Copyright © 2011-2022 走看看