Forum Discussion

tanvi_agarwal's avatar
tanvi_agarwal
Occasional Contributor
12 years ago

How to grab the text on the web page?

Hi,



I am recording tests where I create a booking and a unique ID gets generated at the end of the booking.

How to store that ID in a variable?



Please could someone suggest.



Thanks,

Tanvi
  • Hi Tanvi,



    The fastest way is to ask develop to add a class or a id to the cell itself. For example:



    <td>Your ID:</td>

    <td id="yourid">83575</td>



    Now just search for an object which idStr is "yourid" and retrieve its textContent.





    Other way is to retrieve the "Your ID" cell, and do something like that:



    theId = yourIdObject.Parent.Cell(x, y).innerText;



    Where yourIdObject is the cell with textContent "Your ID", x is yourIdObject RowIndex property, and y is yourIdObject ColumnIndex + 1



    Hope it helped!
  • ArtemS's avatar
    ArtemS
    SmartBear Alumni (Retired)

    Hi, Tanvi


    At first, you need to obtain the web element that holds the needed text and then read the contentText property of the returned object.


    To obtain the desired web element, you may capture it's name with the Object Spy or search for the web object as described in Finding Objects on Web Pages.


     


    For example, the following will output the contents of the copyright not from the footer of SmartBear site:




    var page = Sys.Browser("firefox").Page("http://smartbear.com/");


    var CopyRightElem = page.Form("aspnetForm").Panel("footer").Panel("footer_inner").Panel("footer_nav").TextNode(0);


    Log.Message(CopyRightElem.contentText);


  • Hi Tanvi,



    The fastest way is to ask develop to add a class or a id to the cell itself. For example:



    <td>Your ID:</td>

    <td id="yourid">83575</td>



    Now just search for an object which idStr is "yourid" and retrieve its textContent.





    Other way is to retrieve the "Your ID" cell, and do something like that:



    theId = yourIdObject.Parent.Cell(x, y).innerText;



    Where yourIdObject is the cell with textContent "Your ID", x is yourIdObject RowIndex property, and y is yourIdObject ColumnIndex + 1



    Hope it helped!
  • tanvi_agarwal's avatar
    tanvi_agarwal
    Occasional Contributor
    Hi Artem, 

     

    Thanks for your help.



    The problem which I was facing in grabbing the Content Text is that:

    The ID which gets generated is put in a table and the cell where the ID is displayed is not constant but is dynamic.



    For eg: It is as following:



    Your ID  76565



    But this is for sure that the number I need to grab is the next sibling of the cell which has "Your ID" as its content Text.



    Please could you suggest the way of doing it.



    Thanks,

    Tanvi