# Handling multiple selectors for same object

**URL:** <https://community.smartbear.com/t/handling-multiple-selectors-for-same-object/393>\
**Category:** TestComplete\
**Tags:** test, testcomplete, migrated, object-recognition\
**Created:** [July 2, 2025, 8:44pm UTC](https://community.smartbear.com/t/handling-multiple-selectors-for-same-object/393 "2025-07-02T20:44:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [July 2, 2025, 8:44pm UTC](https://community.smartbear.com/t/handling-multiple-selectors-for-same-object/393/1 "2025-07-02T20:44:05Z")

</div>

> Originally posted by **nastester** on July 02, 2025

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]

```auto
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?

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [July 2, 2025, 8:59pm UTC](https://community.smartbear.com/t/handling-multiple-selectors-for-same-object/393/2 "2025-07-02T20:59:36Z")

</div>

> Originally posted by **scot1967** on July 02, 2025

Hi nastester,

Would it be possible in your case to use variables in a single selector?

[https://support.smartbear.com/testcomplete/docs/testing-with/object-identification/name-mapping/selectors.html](https://support.smartbear.com/testcomplete/docs/testing-with/object-identification/name-mapping/selectors.html)

… If you find my posts helpful drop me a like! 👍 Be sure to mark or post the solution to help others out and/or to credit the one who helped you. 😎

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [July 3, 2025, 7:51am UTC](https://community.smartbear.com/t/handling-multiple-selectors-for-same-object/393/3 "2025-07-03T07:51:37Z")

</div>

> Originally posted by **rraghvani** on July 03, 2025

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

 ![](https://canada1.discourse-cdn.com/flex049/uploads/smartbear_prod/original/1X/dabe1611ef720ffb067912ab31de1e8d0e760a3e.png)

Or combined the XPath,

 ![](https://canada1.discourse-cdn.com/flex049/uploads/smartbear_prod/original/1X/d45be00d68aaf0bc2f4ad219e9be21972b116598.png)

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;

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [July 3, 2025, 4:28pm UTC](https://community.smartbear.com/t/handling-multiple-selectors-for-same-object/393/4 "2025-07-03T16:28:40Z")

</div>

> 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:

```auto
//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.

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [July 10, 2025, 2:40pm UTC](https://community.smartbear.com/t/handling-multiple-selectors-for-same-object/393/5 "2025-07-10T14:40:16Z")

</div>

> Originally posted by **sean4311** on July 10, 2025

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?

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [October 7, 2026, 5:16pm UTC](https://community.smartbear.com/t/handling-multiple-selectors-for-same-object/393/6 "2026-10-07T17:16:47Z")

</div>

Closed on October 7, 2026, 5:16pm UTC

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
