selenium-日曆輸入框(修改readonly屬性兩種方法)

1.修改日曆的時間

        JavascriptExecutor js=(JavascriptExecutor)driver;
        js.executeScript("document.getElementById(\"dateObj\").value=\"2019-11.7\"");

2.日曆當前時間+n顯示

//日曆接口
Calendar day=Calendar.getInstance();
day.add(Calendar.DATE,20);
//輸出yyyy-MM-dd格式
String daySimple=new SimpleDateFormat("yyyy-MM-dd").format(day.getTime());
//因爲日曆不能直接clear,要先移除屬性後再claer()(下面兩行代碼就是不能清除的方法)
((ChromeDriver) driver).executeScript("document.getElementById(\"dateObj\").removeAttribute(\"readonly\")");
 driver.findElement(By.id("dateObj")).clear();
 driver.findElement(By.id("dateObj")).sendKeys(daySimple);//在日曆框中輸入

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章