Forum Discussion

Azeddin_Margani's avatar
Azeddin_Margani
Contributor
9 years ago

To select specific item within a table/container


Hi,

Could someone help, please.  I'm trying to code to identify specific product name then adding it to shopping basket.

 

The mapping name of the container/table that contains the list of product/ticket names is:
Aliases.browser.Page("https://www.busstage.com/regionaltickets/*/"+location+"/megarider").Panel(0).Panel(3).Panel(0).Panel(0).Panel(3).Panel(0).Panel(1).Panel(2).Panel(0).Panel(0).Panel(0)

 

The mapping name of the first product's table is:
Aliases.browser.Page("https://www.busstage.com/regionaltickets/*/"+location+"/megarider").Panel(0).Panel(3).Panel(0).Panel(0).Panel(3).Panel(0).Panel(1).Panel(2).
Panel(0).Panel(0).Panel(0).Panel(0).Panel(0)

 

The mapping name of the first product's [Add to Basket] button.
Aliases.browser.Page("https://www.ukbusstage.com/regionaltickets/*/"+location+"/megarider").Panel(0).Panel(3).Panel(0).Panel(0).Panel(3).Panel(0).Panel(1).Panel(2).Panel(0).
Panel(0).Panel(0).Panel(0).Panel(0).Panel(2).Panel(0).Panel(1).Panel(1).Link(0)

 

My attempted code was by.
1. Using Find("contentText", DDT.CurrentDriver.Value("TicketName") //to identify the spcified ticket name which passed on from spreadsheet
Aliases.browser.Page("https://www.busstage.com/regionaltickets/*/"+location+"/megarider").Panel(0).Panel(3).Panel(0).Panel(0).Panel(3).Panel(0).Panel(1).Panel(2).Panel(0).Panel(0).Panel(0).Find("contentText", DDT.CurrentDriver.Value("TicketName")

2. When the correct product name is identified, then click on [Add to basket] button.

 

The issue i'm having is that i couldn't get the product name identified within the container/table.  This will need to be generic for any product name passed on from spreadsheet.

 

I may need to stor all of the elements in an array.. not exactly sure.


Thanks in advance,
A.M.

  • First suggestion:

    Utilize the "power" of Aliases... currently, you have all your container panels reflected in your Aliases when, in fact, you PROBABLY don't need to actually see them all in your path.  Your NameMapping probably can have them all just fine, but do a little judicial "telescoping" to flatten out your list of objects to make those paths more manageable.

    Second suggestion:

    For getting a list of all the products, you might want to use a FindAllChildren call on that container/table that contains the list of product names.  What you want to do is, in your FindAllChildren call, map out properties that will SPECIFICALLY grab that panel that contains the products... if there are specific text strings in "innerHTML" or something like that, that is what I have used in the past. FindAllChildren will then give you an array of objects that you can then iterate through to find the specific products, links, buttons, etc.

    How do I know this?  Because, in a former life, I had to automate a similar set up of dynamically generated content for tickets on another similar website and that's how I did it.  Now, I did ONE other little trick...

    I had my developer throw in a hidden property on each product's main container that contained that products unique identifier number that I had access to.  Then, if I wanted to find and select a SPECIFIC product, all I needed to do was call "FindChild" and look for that property... and bingo, I had my product.  If you have an amenable developer staff, give that a try.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    First suggestion:

    Utilize the "power" of Aliases... currently, you have all your container panels reflected in your Aliases when, in fact, you PROBABLY don't need to actually see them all in your path.  Your NameMapping probably can have them all just fine, but do a little judicial "telescoping" to flatten out your list of objects to make those paths more manageable.

    Second suggestion:

    For getting a list of all the products, you might want to use a FindAllChildren call on that container/table that contains the list of product names.  What you want to do is, in your FindAllChildren call, map out properties that will SPECIFICALLY grab that panel that contains the products... if there are specific text strings in "innerHTML" or something like that, that is what I have used in the past. FindAllChildren will then give you an array of objects that you can then iterate through to find the specific products, links, buttons, etc.

    How do I know this?  Because, in a former life, I had to automate a similar set up of dynamically generated content for tickets on another similar website and that's how I did it.  Now, I did ONE other little trick...

    I had my developer throw in a hidden property on each product's main container that contained that products unique identifier number that I had access to.  Then, if I wanted to find and select a SPECIFIC product, all I needed to do was call "FindChild" and look for that property... and bingo, I had my product.  If you have an amenable developer staff, give that a try.

    • Colin_McCrae's avatar
      Colin_McCrae
      Community Hero

      The other thing you may run into if you're searching a web table is extra whitespace in the cells.

       

      They often have extra carriage returns and line feeds in there which throw off text matching. Can't remember if wildcarding it out will work when using FindChild/FindAllChilden. If not, you may need to loop through the cells, extract the content text, strip out any whitespace (commonly, these tend to be CHR(10)/CHR(13) and, I think, CHR(14)), and then compare the text.

       

      May not be happening to you, but definitely worth watching out. It's caught me out before ....