Space Time Date
1) a manual input control is not limiting, sendKeys direct call method of writing time data
2) the input space is limited, may be performed to change the value JS attribute value element
javascriptExecutor jsExecutor = (javascriptExecutor) Driver;
jsExecutor.executeScript ( " ... ");
For example 12306
Screenshot below, readonly date space, not allowing manual writing, then removed readonly write time with js
Js verify correct to write, to remove readonly property
Back to see
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.chrome.ChromeDriver;
private static ChromeDriver chromeDriver;
public static void main(String []args) {
openChrome();
//ID 定位
//chromeDriver.findElement(By.id("kw")).sendKeys("Selenium");
//name定位
JavascriptExecutor jsExecutor=chromeDriver;
jsExecutor.executeScript("document.getElementById(\"train_date\").removeAttribute(\"readonly\")");
chromeDriver.findElement(By.id("train_date")).clear();
chromeDriver.findElement(By.id("train_date")).sendKeys("2020-3-29");
}
System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver.exe");
//1.打开浏览器chrome
chromeDriver = new ChromeDriver();
//2.访问12306
chromeDriver.get("https://www.12306.cn/index/");
}
Individual code to achieve the following
chromeDriver.get("https://www.12306.cn/index/");
JavascriptExecutor jsExecutor=chromeDriver;
jsExecutor.executeScript("document.getElementById(\"train_date\").removeAttribute(\"readonly\")");
chromeDriver.findElement(By.id("train_date")).clear();
chromeDriver.findElement(By.id("train_date")).sendKeys("2020-3-29");