Forum Discussion

nastester's avatar
nastester
Regular Contributor
18 days ago
Solved

Handling multiple selectors for same object

My web app has a grid.  I can switch views and the table shows different data.

I want to map the objects in the first row for each column in the grid for both views. 

Currently, I have one object that has two selectors depending on the view:

(//div[@col-id="PolygonDescription" and @role="gridcell"])[1]

(//div[@col-id="TrackingNumber" and @role="gridcell"])[1]

function test() {
  
  //Log Tracking Number 
  Log.Message(NameMapping.Sys.browser.pageCenterView.panelTrackNum.contentText);
  
  //Switch to other tab
  NameMapping.Sys.browser.pageCenterView.buttonTabManifestlistTerritory.Click();
  
  //Log Description
  Log.Message(NameMapping.Sys.browser.pageCenterView.panelTrackNum.contentText);
}

This is currently working but it's little slow because it's trying to find the first selector first. 


My question is, is there a better way to handle this? 

 

 

  • If they share the same parent, then you can specify OR in the name mapping. For example,

    Or combined the XPath,

    Swap the ordering of your selector to suit your needs. You can also adjust the playback auto-wait timeout in code via Options e.g. Options.Run.Timeout = 1000;

4 Replies

  • rraghvani's avatar
    rraghvani
    Icon for Champion Level 3 rankChampion Level 3

    If they share the same parent, then you can specify OR in the name mapping. For example,

    Or combined the XPath,

    Swap the ordering of your selector to suit your needs. You can also adjust the playback auto-wait timeout in code via Options e.g. Options.Run.Timeout = 1000;

  • Hassan_Ballan's avatar
    Hassan_Ballan
    Icon for Champion Level 3 rankChampion Level 3

    I assume that your "NameMapping.Sys.browser.pageCenterView.panelTrackNum" node have two OR XPath lines as in rraghvani​ screen shot. As the first selector is not available, TestComplete would wait for the time out using the default global setting of 10 seconds before it proceeds to the next selector. You will notice that first selector and the click went fast and the second selector is slow after 10 seconds.

    The combined selector rraghvani​ provided is the solution; however, since you are only interested with the first occurrence and that XPath results, TestComplete always interacts with the first occurrence and there is no need to specify it.

    I would write it like this:

    //div[@col-id="PolygonDescription" and @role="gridcell"] | //div[@col-id="TrackingNumber" and @role="gridcell"]

    💬 If a response helped you out, don’t forget to Like it! And if it answered your question, mark it as the solution so others can benefit too.

  • Hi nastester​

    The solutions provided in the the thread would definitely help in interacting with the different grids your web app uses. Do any of these solutions help with the issue?