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语句改变页面元素属性值的方式将日期控件修改成可编辑状态,以便完成脚本直接输入日期来进行日期选择。
  • 相关阅读:
    DataStructure期末复习小tips
    MediaPlayer
    Java中Calendar的用法
    C++小tips
    函数返回局部变量的问题
    framebuffer
    MTK gpio adb 控制 和 查看中断INDEX
    emmc
    No 'Access-Control-Allow-Origin' header is present on the requested resource.解决方法(亲测有效)
    JavaScript的Promise必须要会的几个点
  • 原文地址:https://www.cnblogs.com/sleeping-cat/p/8278485.html
Copyright © 2011-2022 走看看