Forum Discussion

sarya's avatar
sarya
Frequent Contributor
15 years ago

how to retrieve current date from a date field from web page

Hi,



I have a webpage from where I want to retrieve the date that I have marked in the screenshot .As this date keeps on changing ,how can I recover the current value from the webpage.

Also there is another screenshot  "history table" from which the first value of the execution date needs to be compared with the value that gets retreived from the webpage as described in the screenshot "dateformat" .

The area marked in second screenshot is the table as recognised by the test complete.This is how innertext appears for the table .

"

Job Name R2W_Version_Retention

Filter


Execution DateStatusScheduled

08 Feb 2010 02:45 PM EST CompletedNo

08 Feb 2010 02:40 PM EST CompletedNo

08 Feb 2010 11:20 AM EST CompletedYes

08 Feb 2010 10:40 AM EST CompletedNo

08 Feb 2010 10:30 AM EST CompletedNo

08 Feb 2010 10:30 AM EST CompletedNo

08 Feb 2010 10:25 AM EST CompletedNo

08 Feb 2010 10:25 AM EST CompletedNo

08 Feb 2010 10:25 AM EST CompletedNo

08 Feb 2010 10:25 AM EST CompletedNo

08 Feb 2010 10:25 AM EST CompletedNo

08 Feb 2010 10:20 AM EST CompletedNo

08 Feb 2010 10:05 AM EST CompletedYes

25 Jan 2010 11:20 AM EST CompletedYes



"



Thanks,

Sumedha


6 Replies

  • Hi,



    You need to iterate through records in your table, find the needed one (for example, by column name and row index) and obtain the value from its innerText property. See the "Parsing HTML Tables" help topic for details.

  • sarya's avatar
    sarya
    Frequent Contributor
    Hi,



    I figured out  a way to find a static value from the table.How can I find  a dynamic value from the table for the cell having innertext as "user2" from the table as attached in the screenshot .The code belows brings up all the values from the rows with cell0 value .What can I do if I want to retrieve only one particular value from all the values in the cell0 .For example I need to find the cell0 with innertext as "user2" that is part of the full string "user2 4 1 1" How to write it in the below if loop.

    page.NativeWebObject.Find("namePropStr","groups32.gif","IMG").Click();


    group = page.NativeWebObject.Find("innerHTML","TestGroup","A");


    tbl = page.document.frames.Frame("main").document.all.Item("table_1");


    for(i = 0; i < tbl.rows.length; i++)


    { for (j = 0; j < tbl.rows.item(i).cells.length; j++)


    {


    a = tbl.rows.item(i).cells(0).innerText;


    Log.Message(a);


    }


  • Hi,



    You need to compare the value in the target cell with the needed value. Inside your loop, use code like this:

    ...

    a = tbl.rows.item(i).cells(0).innerText;

    if(a.indexOf("user2") > -1) Log.Message("Found: " + a);

    ...


  • Hi,



    You need to compare the value in the target cell with the needed value. Inside your loop, use code like this:

    ...

    a = tbl.rows.item(i).cells(0).innerText;

    if(a.indexOf("user2") > -1) Log.Message("Found: " + a);

    ...


  • sarya's avatar
    sarya
    Frequent Contributor
    Hi Jared,



    Thanks,This code worked fine .I have one more doubt : Now that I have verified the first cell ,I want to see if the third cell value is also "user2".I used a.parent.childNodes[2] but it returned an exception saying it is null or not an object. I want to verify in the loop usind AND that condition will be true when first cell and third cell value match a particular value .



    for(i = 0; i < tbl.rows.length; i++)


    { for (j = 0;j <=0; j++)


    {


    a = tbl.rows(i).cells(0).innerText;


    if((a.indexOf("TestGroup") > -1))


    Log.Message("Found: " + a);


    b = a.Parent.childNodes[2];

    }


    }


  • Hi,



    You just need to obtain the value of the third cell as you do this with the first cell:

    ...

    a = tbl.rows(i).cells(0).innerText;

    //...

    b = tbl.rows(i).cells(2).innerText;

    if(a == b) // match

    ...