目的:以12306网站的日期控件为例,定位该控件并输入自定义日期。
思路:
1. 查看日期控件元素,发现日期输入框有readonly属性(如上图所示);
2. 利用 js 去掉 readonly 属性,将控件变为可编辑状态;
3. 清空输入框中数据(如果有),输入自定义日期。
代码:
package com.ceres.demos;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class HandleDatePicker {
public static void main(String[] args) thr