Java 如何在文本框中输入当前日期和时间

Java 如何在文本框中输入当前日期和时间,java,selenium,Java,Selenium,我想在文本框中输入当前日期和时间以及秒数;我该怎么做 我写的代码如下所示,但它只是输入我在send key中传递的字符串值,这清楚地表明我没有在正确的轨道上 有什么建议吗 // Create object of SimpleDateFormat class and decide the format DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy "); //使用日期()获取当前日期时间 日期

我想在文本框中输入当前日期和时间以及秒数;我该怎么做

我写的代码如下所示,但它只是输入我在send key中传递的字符串值,这清楚地表明我没有在正确的轨道上

有什么建议吗

// Create object of SimpleDateFormat class and decide the format
        DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy ");
//使用日期()获取当前日期时间 日期=新日期()


可能您应该尝试使用LocalDateTime.now()或Calendar.getInstance()而不是new Date(),因为Date API方法存在缺陷且已弃用。

可能您应该尝试使用LocalDateTime.now()或Calendar.getInstance()而不是new Date(),因为Date API方法存在缺陷且不推荐使用。

collection\u title.sendKeys(“date1”)中您没有使用变量date1,而是使用字符串“date1”-date1周围不应该有引号

它应该是这样工作的:

DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
Date date = new Date();
collection_title.sendKeys(dateFormat.format(date));

collection_title.sendKeys(“日期1”)您没有使用变量date1,而是使用字符串“date1”-date1周围不应该有引号

它应该是这样工作的:

DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
Date date = new Date();
collection_title.sendKeys(dateFormat.format(date));