zoukankan      html  css  js  c++  java
  • python+selenium2自动化---通过js脚本给时间控件赋值

    大多数的时间控件都加上了readonly属性,不能直接修改,只能通过控件选择

    在自动化测试过程中,可以通过js脚本直接输入对应的时间,省去操作控件悬浮框

    思路:

    1、获取掉时间输入框后,去掉readonly属性;

    2、通过js脚本赋值

    下面以12306首页出发日期为例实践一下:

    js执行过程:

    转换成对应的python代码:

    from time import sleep
    
    from selenium import webdriver
    
    class TestCase():
        def __init__(self):
            self.driver = webdriver.Chrome()
            self.driver.get('https://www.12306.cn/index/')
            self.driver.maximize_window()
    
        def test01(self):
            self.driver.execute_script("document.getElementById('train_date');a.removeAttribute('readonly')")
            self.driver.execute_script("document.getElementById('train_date').value='2020-08-30'")
            sleep(2)
            self.driver.quit()
    
    if __name__ == '__main__':
        TestCase().test01()
  • 相关阅读:
    负外边距--转载
    研究Dropbox Server端文件系统
    Bluetooth Profile for iPhone from the functional perspectives
    Somebody That I Used to Know
    复合查询
    聚合查询
    Filter查询
    ES基本查询
    ES版本控制
    ES基本操作
  • 原文地址:https://www.cnblogs.com/canghai1024/p/13475331.html
Copyright © 2011-2022 走看看