Selenium自动化之操作日期控件(二)定位点击

本文详细介绍了如何在Selenium自动化测试中操作和点击日期控件,通过精准定位实现对日期选择功能的自动化控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#操作日期控件,定位点击

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):
        # 启动ie浏览器
        self.driver = webdriver.Ie(executable_path = "g:\\IEDriverServer")

    def test_datePicker(self):
        url = "http://jqueryui.com/resources/demos/datepicker/other-months.html"
        # 访问指定的网址
        self.driver.get(url)
        try:
            # 创建一个显示等待对象
            wait = WebDriverWait(self.driver, 10, 0.2)
            # 显示等待判断被测试页面上的日期输入框是否可见并且能被点击
            wait.until(EC.element_to_be_clickable((By.ID, 'datepicker')))
        except TimeoutException as e:
            # 捕获TimeoutException异常
            print (traceback.print_exc())
      
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值