Why it Matters
To display content relative to your existing application’s elements or to capture feature usage events, you need to define an element selector so that GuideWhale can reference these elements later. This allows you to precisely target any element on the page and display content in the right context.Search Fallback
When content relies on a target element to be shown, it’s essential to define a fallback action to take when the target element is not found. This ensures that your content is displayed correctly, even if the target element is not found on the target page. The fallback action can either dismiss the content or fallback to another position that doesn’t require the target element.Target Element Selection
CSS Selector
GuideWhale supports flexible target element selection for displaying content:- Automatic: The Chrome extension generates a CSS selector for the selected element automatically.
- Manual: Users can enter a custom CSS selector to precisely target any element on the page.
Automatic
The Chrome extension automatically generates an optimal CSS selector when you visually select an element from your application.Manual
When you need precise control over element selection, you can manually define a CSS selector. This is useful when the automatic selector doesn’t capture the right element or when you want to target elements dynamically.Using Browser Console to Inspect Elements
Before writing a CSS selector, you need to inspect the HTML structure of your target element:-
Open Developer Tools
- Right-click on the element you want to target
- Select “Inspect” or “Inspect Element”
- Alternatively, press
F12orCmd+Option+I(Mac) /Ctrl+Shift+I(Windows/Linux)
-
Locate the Element
- The Elements/Inspector tab will open with the element highlighted
- Examine the element’s HTML structure, classes, IDs, and attributes
- Note the parent and sibling elements for context
-
Test Your Selector
- Open the Console tab in Developer Tools
- Use
document.querySelector('your-selector')to test if your selector finds one element - Use
document.querySelectorAll('your-selector')to see all matching elements - If the element is highlighted in the browser, your selector is correct
CSS Selector Types
GuideWhale supports all standard CSS selectors. Here are the most common types:1. ID Selector
Targets an element with a specific ID. IDs should be unique on a page. Syntax:#elementId
Example:
2. Class Selector
Targets elements with a specific class. Multiple elements can share the same class. Syntax:.className
Example:
3. Element Selector
Targets all elements of a specific type. Syntax:elementName
Example:
4. Attribute Selector
Targets elements with specific attributes or attribute values. Syntax:[attribute] or [attribute="value"]
Examples:
5. Descendant Selector
Targets elements that are descendants of another element. Syntax:ancestor descendant
Example:
6. Direct Child Selector
Targets elements that are direct children of another element. Syntax:parent > child
Example:
7. Multiple Classes
Targets elements with multiple specific classes. Syntax:.class1.class2
Example:
8. Pseudo-classes
Targets elements in a specific state. Syntax:selector:pseudo-class
Examples:
9. Combining Selectors
You can combine multiple selectors for more specific targeting. Examples:Best Practices
-
Use Stable Selectors
- Prefer
data-*attributes or IDs over auto-generated classes - Avoid selectors based on dynamic classes (e.g.,
css-123abc)
- Prefer
-
Keep It Simple
- Use the shortest selector that uniquely identifies the element
- Avoid overly complex selectors that may break easily
-
Test Thoroughly
- Always test your selector in the browser console
- Verify it works across different states (logged in/out, different pages)
-
Consider Dynamic Content
- For lists or repeated elements, use
:nth-child()or attribute selectors - Account for elements that may load asynchronously
- For lists or repeated elements, use