Shadow-Piercing descendant combinator, '/deep/' , including '::shadow' pseudo elements, are being deprecated so how do we pierce the Shadow DOM?
Rather than using
<link />, I'd suggest you to use css @imports inside shadow root to load external stylesheets where ever needed.
I have written an answer here on the topic. Quoting it below for reference.
You can create a style.css and import it in your components by putting
a css @import in your template. There won't be multiple network calls,
since browser is going to cache it when your first component loads and
for subsequent components it will picked from cache.
What's the substitute for ::shadow and /deep/?
/deep/ were removed for breaking encapsulation.
The substitutes are:
- CSS variables.
It already works natively with the recently launched Google Chrome 49. Read here:
:host-context. Read here: http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom-201/
The use of /deep/ and in Angular 2
Is /deep/ here to stay? Do we have any source, a quote, or anything from any specification saying that it will be adopted? Or if it has officially been deprecated?
/deep/syntax is obsolete, last seen in css-scoping in 2014, and its replacement
>>>was deprecated about half a year ago in Chrome 45.
The entire concept of the shadow-piercing descendant combinator is slated to be removed from the Shadow DOM entirely. Implementations may either remove it altogether or alias it to the regular descendant combinator (which depending on how the Shadow DOM is implemented in the future may or may not make sense).
Can we suppress this error in Visual Studio Code without all-together disabling syntax checking?
Angular allows both in emulated view encapsulation for compatibility purposes, but authors are strongly encouraged to use
>>>going forward, since
/deep/is technically invalid now, and therefore unsupported in native view encapsulation.
How and where to use ::ng-deep?
/deep/ “shadow-piercing” combinator can be used to force a style down to
child components. This selector had an alias >>> and now has another one called ::ng-deep.
/deep/ combinator has been deprecated, it is recommended to use
<div class="overview tab-pane" id="overview" role="tabpanel" [innerHTML]="project?.getContent( 'DETAILS')"></div>
it will be applied to child components
How to automate shadow DOM elements using selenium?
There is a very good plugin that can be used with selenium project shadow-automation-selenium. It helps in writing much better, readable and maintainable code. Using this you can access multi level of shadow DOM (upto 4 levels ) . This uses simple css selector to identify elements.
WebElement findElement(String cssSelector) : use this method if want single element from DOM
List<WebElement> findElements(String cssSelector) : use this if you want to find all elements from DOM
WebElement findElements(WebElement parent, String cssSelector) : use this if you want to find a single elements from parent object DOM
List<WebElement> findElements(WebElement parent, String cssSelector) : use this if you want to find all elements from parent object DOM
WebElement getShadowElement(WebElement parent,String selector) : use this if you want to find a single element from parent DOM
List<WebElement> getAllShadowElement(WebElement parent,String selector) : use this if you want to find all elements from parent DOM
boolean isVisible(WebElement element) : use this if you want to find visibility of element
boolean isChecked(WebElement element) : use this if you want to check if checkbox is selected
boolean isDisabled(WebElement element) : use this if you want to check if element is disabled
String getAttribute(WebElement element,String attribute) : use this if you want to get attribute like aria-selected and other custom attributes of elements.
void selectCheckbox(String label) : use this to select checkbox element using label.
void selectCheckbox(WebElement parentElement, String label) : use this to select checkbox element using label.
void selectRadio(String label) : use this to select radio element using label.
void selectRadio(WebElement parentElement, String label) : use this to select radio element from parent DOM using label.
void selectDropdown(String label) : use this to select dropdown list item using label (use this if only one dropdown is present or loaded on UI).
void selectDropdown(WebElement parentElement, String label) : use this to select dropdown list item from parent DOM using label.
How to use this plugin:
You will have to dependency in your project.
for html tag that resides under a shadow-root dom element
You can use this code in your framework to grab the textarea element Object.
Shadow shadow = new Shadow(driver);
WebElement element = shadow.findElement("properties-page#settingsPage>textarea#textarea");
String text = element.getText();