Skip to content

Support for selecting elements inside shadow dom via ExternalSelectorConfig? #31

Description

@GrayedFox

Hello there, awesome little library you have built!

I am trying to construct some selectors based on an injected web-component that uses the shadow dom to shield the component from unwanted style changes.

This would be the shadow host:

class ParentSelector {
  @By.Type('product-host', { eq: 0 }) static base: Selector;
}

And these would be the elements within the shadow dom:

const testAttribute = { attribute: 'data-testid', parent: ParentSelector.base };

class ProductCardSelectors {
  @By.Attribute('product-title', testAttribute) static title: Selector;
  @By.Attribute('product-images-slide', testAttribute) static image: Selector;
  @By.Attribute('product-card-add', testAttribute) static addButton: Selector;
  @By.Attribute('product-price', testAttribute) static price: Selector;
  @By.Attribute('product-merchant', testAttribute) static vendor: Selector;
  @By.Attribute('stock', partAttribute) static outOfStockBadge: Selector;
}

I know I can reference the parent by passing in parent config option - but how can I tell the ProductCardSelectors class to traverse the shadow dom?

Do you have a recipe or workaround for this perhaps?

Cheers 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions