-1

我需要得到明天的日期并且需要存储在 selenium IDE 中。

任何人都可以帮助这个。

4

4 回答 4

2

你可以像这样得到明天的日期:

var d = new Date();
d.setDate(d.getDate() + 1)
console.log(d.toLocaleDateString();) //or d, depends on how you want that date

并将其存储在 Selenium 中,也许可以帮助您

于 2012-07-23T06:44:26.850 回答
0

使用 selenium [html] 脚本,您可以使用它。简单来说就是获取现在的日期/时间,加上86400000毫秒(一天的毫秒数=24h*60m*60s*1000ms)

<tr>
    <td>storeEval</td>
    <td>d=new Date(new Date().getTime()+86400000)</td>
    <td>tomorrow</td>
</tr>
<tr>
    <td>echo</td>
    <td>${tomorrow}</td>
    <td></td>
</tr>
于 2014-09-10T17:47:58.537 回答
0

对于上述问题,我已经在 codebins 上完成了 bin 解决方案。它的演示链接如下:

演示: http ://codebins.com/bin/4ldqp9v

请通过添加您的评论告诉我此解决方案是否对您有帮助。

HTML:

<div id="panel">
  <input type="text" size="15" id="txtdate" name="txtdate" />
  <input type="button" id="btndate" name="btndate" value="Show Tommorrow Date" />
  <div id="result">
  </div>
</div>

Javascript:

var dateBtn = document.getElementById('btndate');

dateBtn.onclick = function() {
    var strdate = document.getElementById('txtdate').value;
    if (strdate != "" && strdate != null && typeof(strdate) != "undefined") {

        if (isValidDate(strdate)) {

            var userdate = new Date(strdate);
            var newdate = new Date(userdate.getTime() + 1 * 24 * 60 * 60 * 1000);

            document.getElementById("result").innerHTML = "Tomorrow date is: " + (newdate.getMonth() + 1) + "/" + newdate.getDate() + "/" + newdate.getFullYear() + " [MM/dd/YYYY]";
        }

    } else {
        alert("Invalid date format value..!");
        return false;
    }
}

//Function for checking valid date format/value.
function isValidDate(dateStr) {

    // Checks for the following valid date formats:
    // MM/DD/YYYY
    // Also separates date into month, day, and year variables
    var datePat = /^(\d{2,2})(\/)(\d{2,2})\2(\d{4}|\d{4})$/;

    var matchArray = dateStr.match(datePat); // is the format ok?
    if (matchArray == null) {
        alert("Date must be in MM/DD/YYYY format")
        return false;
    }

    month = matchArray[1]; // parse date into variables
    day = matchArray[3];
    year = matchArray[4];
    if (month < 1 || month > 12) { // check month range
        alert("Month must be between 1 and 12");
        return false;
    }
    if (day < 1 || day > 31) {
        alert("Day must be between 1 and 31");
        return false;
    }
    if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) {
        alert("Month " + month + " doesn't have 31 days!")
        return false;
    }
    if (month == 2) { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day == 29 && !isleap)) {
            alert("February " + year + " doesn't have " + day + " days!");
            return false;
        }
    }
    return true; // date is valid
}

演示: http ://codebins.com/bin/4ldqp9v

于 2012-07-23T14:00:14.270 回答
0
Selenium.prototype.doGenerateTomorrowDate = function( varName1, varName2 ) 
{
    var currentDate = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
    var day = currentDate.getDate()
    var month = currentDate.getMonth() + 1
    var year = currentDate.getFullYear()
    var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
    var month = monthNames[month];
    storedVars[ varName1 ] =  day;
    storedVars[ varName2 ] =  month;
};

<tr>
    <td>generateTomorrowDate</td>
    <td>x</td>
    <td>y</td>
</tr>
<tr>
    <td>echo</td>
    <td>${x}</td>
    <td></td>
</tr>
<tr>
    <td>echo</td>
    <td>${y}</td>
    <td></td>
</tr>

这将在明天和明天返回。

于 2012-07-24T09:08:55.433 回答