Java的Selenium的特殊元素操作与定位之时间日期控件

分为两种情况:

  • 控件没有限制手动输入,则直接调用sendKeys方法写入时间数据
java 复制代码
//时间日期控件处理
chromeDriver.get ("https://www,fliggy,com/?ttid=sem.000000736&hlreferid=baidu.082076&route source=seo");
chromeDriver.findElement (By.xpath("//form[@id='J FlightForm']//input [@name='depDate']")).sendKeys ("2020-01-10");
  • 控件有限制输入,则可以执行一段js来改变元素的value属性值
java 复制代码
● JavascriptExecutor jsExecutor=(JavascriptExecutor) driver;
● jsExecutor.executeScript("...")
java 复制代码
//限制输入的时间日期控件
chromeDriver.get("https://www.12306.cn/index/");
//javascript执行对象
JavascriptExecutor javascriptExecutor =(JavascriptExecutor) chromeDriver,
javascriptExecutor .executescript ("document.getElementById(\"train date\").removeAttribute(\"readonly\") ")
Thread.sleep(1000);
chromeDriver.findElement(By.id("train date")).clear();
Thread.sleep(1000);
chromeDriver.findElement (By.id("train date")).sendKeys("2020-01-10");
相关推荐
键盘歌唱家14 分钟前
Spring AI 入门分享:它和“直接调 API“到底差在哪
java·人工智能·spring
宸丶一1 小时前
Day 10:LangGraph - Agent 的图执行引擎
java·windows·python
hikktn1 小时前
Excel 导出 OOM 预防实战:30 万行从堆溢出到 50MB 的演进
java·excel·easyexcel
风味蘑菇干1 小时前
WTomcat服务器
java·服务器
燕-孑1 小时前
tomcat详解(基础到高级生产)
java·tomcat
码不停蹄的玄黓1 小时前
Spring Bean 生命周期
java·后端·spring
西安邮电大学1 小时前
分治算法详细讲解
java·后端·其他·算法·面试
摇滚侠2 小时前
Mybatis 入门到项目实战 搭建 MyBatis 框架 01-14
java·tomcat·mybatis
码不停蹄的玄黓2 小时前
SpringBoot 全局异常处理器实现
java·spring boot·后端
小高学习java3 小时前
事务的边界问题,如何判断数据回滚时机。
java·数据库·后端