Selecting the right element

Use CSS selectors to ensure the right element (including dynamic) on the page is selected for your Experience to appear or trigger correctly

Chameleon Team avatar
Written by Chameleon Team
Updated over a week ago

One of the most powerful abilities of Chameleon is the possibility to anchor or trigger Steps based on your page elements. As every application is unique, you can further adjust selectors to ensure your Experiences display correctly.

All to deliver Experiences that are contextual and guide your users to discover clear moments of value in your product.

🧑‍💻 Ask your Developer to help: elements selection can get tricky but a developer on your team can help out by adding an ID (or an attribute) to that element, to make sure it will always target correctly. You can also contact us if you get stuck and we can take a look!

📺 Check out the video below to see how element selection works in Chameleon.

This video does not show our latest product and capabilities. We'll soon update our videos to match what Chameleon is today.

Elements are essentially different boxes of content on a page defined by HTML and CSS code. Chameleon uses on-page elements to establish where and when an Experience should show up, along your defined user Segments, or set triggers for example.

By leveraging the presence or absence of elements, you can show users specific parts of your interface and help them discover more features. 😉

Here are a few examples of how you can leverage elements in Chameleon: 

  • require an element is present or clicked to show a Step; 

  • position a Tour Step by snapping it to an element on the page; 

  • highlight a particular element; 

  • fire a click on an element when a user clicks the "Next" button in a Step; 

  • require an element to be clicked to proceed to the next Step of the Tour; 

  • track clicks and use them for targeting Tours; and more.

All these cases require Chameleon to correctly identify and save the relevant element on the page. We are built to handle this, but it's useful to know how it works, in case you need to make a manual adjustment 😊

Using the point-and-click editor you can select any element that is present on your page, including those in menus. Once you select one, Chameleon will know to condition your Step to the presence, absence, or unique content of this element.

Chameleon identifies the element you have selected using CSS Selectors: these are code identifiers that target an HTML component on the page. 

In the image above, "body" is the CSS Selector, but there are many more you may encounter. Some of the most common include the element selector (e.g. <div>, <p> etc.), <class> and <id>. Together these can help uniquely identify an element on the page. 

If you find that your element isn't correctly identified, you can adjust it further to fit the exact one you want to target. Read more about selecting and adjusting your elements below. 👇

Whenever there is the opportunity to Select an element, you will see the same point-and-click flow. Hover your mouse over your page to identify the element your want to leverage.

The available elements will have a green outline appear around and you can simply click to select one. Click "Confirm" in the Builder panel that opens up and your Step will be anchored or conditioned to be shown by this element.

In some cases, you may not see the correct element highlighted (with the green outline) or the match may be incorrect if you return later. So, it might be necessary to manually Adjust the element to accurately match the intended one. 

The Adjust element panel will give you three broad ways to input the correct selectors:

  1. Specify a specific element in a hierarchy

  2. Specify your element further via single selectors

  3. Add custom CSS path

👉 You can also include here any data attributes to pinpoint the right element. This is especially useful if your product has dynamic classes, as you can include a unique attribute to help Chameleon identify specific elements when building out Experiences.

As you adjust the CSS Selectors, the matching will be updated in real-time and the matching element will show the green outline. You can use this as a guide to check whether you've made the correct adjustments to match the intended element. 

If your element selection contains multiple matches (for example, you may be struggling to specify a specific menu item in a list of menu options), you can use this option to specify which element in the hierarchy to select.

You can use your keyboard's up/down arrow keys and watch the green outline move from element to element on your screen until it lands on your intended selection.

We don't recommend using the HTML hierarchy option if any of the classes or elements on the page/or in the hierarchy are dynamic and can change. This can cause the hierarchy to break and your selected element may no longer be the correct one.

This option allows you to easily edit or add an individual selector to help you define the right element. 

For example, you may want to use HTML Hierarchy and you can check the box, or you may want to change the 'text' value or add an additional 'id'. You can do all that easily here. 

The available options to adjust how this element is selected are:

  • HTML hierarchy: all of html tags from this element up to the <body> tag. This helps us locate the element on the page and typically consists of <div> tags and their classes.

  • tag: the type of html tag associated with this specific element, such as a, input or h1 

  • text: the text string this element contains, such as "Sales by day"

  • id: the unique ID, such as "chart-overview-1234"

  • class: any class names, such as "chart-main"

  • href: any link associated, such as ""

  • title: the title, such as "Chart"

  • type: the type, typically found on <button>  and <input>  fields, such "text" or "email"

  • name: the name, such as "Top sales"

  • data: add a unique attribute (chmln) to elements that you can leverage in Chameleon

👉 We recommend you add data-chmln to the specific element you're trying to leverage and fill in the data value based on the element you want to target.

In the example below 👇 I want to add an attribute to the 'New note' element, so I add chmln in the data field and new-button in the value field.

💡 You can apply this to any element you want to target, including your inline Launcher widgets which you can use to launch further guidance or Actions.

In this case, you would use the same principle, but update your value to match your element: data-chmln="help-launcher"

When you're positioning a Step or Tooltip on the page, the element selector is used to click on a particular element and place your Experience next to that element. This feature should work in 99% of the cases that you'll run into.

You can also fully edit the CSS path to identify the correct element. This is great for a few use cases:

  • you need need a unique or very custom configuration for your selector

  • your website structure changes frequently, and you have a very specific CSS class or ID that can be used to identify the element

  • the target element is not the top element, and you're not able to select the target element

To use this, simply select the Add custom CSS path option and update (or add) your desired CSS code here.

If you're having difficulty getting the CSS Path for your element, you can follow these instructions to copy a CSS Path to that element. You may need to make some adjustments.

  1. Open up a Firefox browser and go to the page in your app where you're adding the Experience

  2. Open up the Developer Tools ( on Mac hit cmd + option + I ) and click the Select Element icon in the top left corner, which looks like a mouse arrow

  3. Select your target element, which will likely be the same container element you found using our Element Selector

  4. Within the Inspector hover over the nearby elements until you highlight your desired element on the page

  5. Right-click ( ctrl-click ) on that element in the Inspector and select Copy > CSS Path

  6. Go back to the Builder within your Chrome browser, and paste that into the Add custom CSS Path section. You may need to modify this path, for example,

    • if it's not finding any elements that match, start from the beginning of the CSS Path and delete the first elements one at a time. Select everything up to the first space ( " " ) and delete, then keep deleting until you see that it's selected your element.

    • if it's finding multiple elements that match, go back and see if there's anything else identifying about your element. For example, if it's an image, there may be some alt text you can use to specify.

It's not currently possible to select multiple elements together for highlighting or for other use cases. However, in some cases, you can generalize the element selection so that it matches multiple elements, and any of these individually can be used. 

💡 You can generalize by adjusting the selectors (e.g. removing specifying criteria such as text or href of any element) once the element has been selected.

In the following cases, when multiple elements match, the first matching element will be used. 

  • "Require element on page" (learn how this works here)

  • Show Step "On hover" or "On click" of an "Icon" / "Label" / "Custom icon"

  • Position the Step "Anchor to Trigger element" (if "Icon" / "Label" / "Custom icon" used) 

  • Position the Step "Anchor to other element"

  • Defined events (used for targeting or conversion tracking)

  • Button action "Click element"

This is because when the icon/label/custom icon or Step needs to display immediately upon page load, a fixed element is required.

However in the following cases, when multiple elements match, you can choose to use only the first or any elements that match:

  • Show Step "On hover" or "On click" of an "Existing element"

  • Position the Step "Anchor to Trigger element" (if "Existing element" used) 

  • Complete Experience by clicking "Specific element"

You can use this to allow a user to click/hover on any one of many elements before the Step appears, adjacent to that element, or by allowing them to click any one of a number of elements to advance from the current Step.

If you have several elements on the page that are matching, and you want to select the last one you can modify the custom CSS as described below.

  1. Select the element on the page

  2. Go to the "Add custom CSS" section

  3. Delete the last part of the CSS path until it matches all of the relevant elements on the page

    • For example, if several buttons all had the same text you would remove all the custom CSS up to the text on those buttons or the class name for those buttons

  4. Add in ":last" (without the quotes) to the end of that path

🤝 As always, be sure to test it and make sure that it works live as you expect it to.

Example use: let's say this was the Custom CSS that showed up when you select one item in a menu. "Components" is the first match, but we want "Tables":

body > div[class*="primary__wrapper-sc-"] > > li.nav-item > a.nav-link.collapsed[href="#"]

You would then click the backspace button on this until multiple items are selected. In this case, we delete ".nav-link.collapsed[href="#"]" off the end:

body > div[class*="primary__wrapper-sc-"] > > li.nav-item > a

👉 You can use the nth option here as well, and specify the correct number for the element you want to select.

Now we'll add in "a:last" to only select the last element, "Tables":

body > div[class*="primary__wrapper-sc-"] > > li.nav-item > a:last

And you'll notice Chameleon identifying the "Tables" element correctly now.

To uncover what CSS selectors are used for a particular element, you can "Inspect" it after right-clicking on that element. The HTML content and related CSS Selectors are then shown in the browser's console, as below. 

💡The value fields use a 'contains' match -- so you can use a subset of the actual value of the field to help identify it.

A dynamic element has attributes that keep changing with every page refresh, like pages that display content based on different visitors. Chameleon works well with dynamically changing elements too and you can leverage them just as static elements when positioning your Experiences or conditioning their display.

In some cases, selector values (e.g. for class name) change each time the application is deployed. This means that the selector values are not persistent, and so the element selection may not continue to match. If this happens for your application (relevant for some React apps) then you can uncheck the dynamic / changing selectors (such as the 'HTML hierarchy') from the element match criteria.

Use trial-and-error to uncheck selectors that might be the culprits (we suggest starting with 'HTML hierarchy' and 'class'). If removing these conditions causes the element to be matched again, you'll see a green border around that matching element on the page.

ℹ You can also add a data attributes to your elements when adjusting them in Chameleon, to help pinpoint the right one, while selecting one on your page.

🧑‍💻 Your developer can help here, or you can wait for the application to be updated (before publishing a Tour) and then make an adjustment.

Find out more

Did this answer your question?