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?
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;
Originally posted by Hassan_Ballan on July 03, 2025
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.
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?