开发者

Watin:Get date from textfield

I have a textfield that has a开发者_StackOverflow中文版 date with the format "12/23/2010".Is there away for me to get the number 23 using watin ie get number from textfield;i'm gonna use it like this. 1.Get datetime 12/23/2010 and get number '23' 2.substract 2 from 23 and store it somewhere[ie: 23 - 2 = 21] 3.Insert the new datetime number [ie:12/21/2010 ]

    string myDate = browser.TextField(Find.ByName("myTextField")).Value;
    DateTime time =  = new DateTime();
    time2 = time - 2;
    browser.TextField(Find.ByName("myTextField")).TypeText(time2);

Is this possible?or should i be looking to another way.Ask the user to insert the data instead.


Try this :

string myDate = browser.TextField(Find.ByName("myTextField")).Value;
DateTime time =  = new DateTime();
if(DateTime.TryParse(myDate, out time);) {
     Console.WriteLine(time.Month);
}
else {
   //Not a valid date.
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜